Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

url: pathToFileURL duplicates root slash across platforms and misses empty extended UNC servername

Geschlossen Anfängerfreundlich
#67,091 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@JoaoMarcos44 arbeitet bereits daran.

Seit 28.10.2026.

  • #67092 von @JoaoMarcos44 — offen

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
javascript, node.js
Bereich
api, backend

Rechercherichtung

Beginne in lib/internal/url.js an den beiden im Issue genannten Stellen und lies dann die umgebende pathToFileURL()-Logik sowie die zugehörigen URL-Tests. Reproduziere die Fälle mit Root-Slash mit { windows: false } und { windows: true } und prüfe, wie bestehende Tests leere erweiterte UNC-Servernamen abdecken. Fertig ist die Arbeit, wenn plattformübergreifende URLs genau einen abschließenden Slash haben und der leere Servername ERR_INVALID_ARG_VALUE auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Version

v22.16.0 (also reproduces on main)

Platform
Microsoft Windows NT 10.0.26100.0 x64 (and POSIX platforms when passing `{ windows: true }`)
Subsystem

url

What steps will reproduce the bug?

url.pathToFileURL() has two bugs in lib/internal/url.js:

  1. Cross-platform root path trailing slash duplication (resolved[resolved.length - 1] !== path.sep):
    When restoring trailing slashes stripped by path.resolve(), pathToFileURL() compares the last character of resolved against the host platform's path.sep instead of the target separator (windows ? '\\' : '/'):

    // On Windows (where path.sep === '\\'):
    console.log(url.pathToFileURL('/', { windows: false }).href);
    // Prints: 'file:////' (4 slashes instead of 'file:///')
    
    // On POSIX / Linux / macOS (where path.sep === '/'):
    console.log(url.pathToFileURL('C:\\', { windows: true }).href);
    // Prints: 'file:///C://' (double trailing slash instead of 'file:///C:/')
    
  2. Extended UNC path empty servername bypass (hostnameEndIndex === 2):
    For extended UNC paths (\\?\UNC\...), prefixLength is 8, but the empty servername check hardcodes if (hostnameEndIndex === 2) instead of if (hostnameEndIndex === prefixLength):

    console.log(url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).href);
    // Prints: 'file:///share' instead of throwing ERR_INVALID_ARG_VALUE ('Empty UNC servername')
    
How often does it reproduce? Is there a required condition?

Always (100% reproducible).

What is the expected behavior? Why is that the expected behavior?
  • url.pathToFileURL('/', { windows: false }).href should return 'file:///' on all platforms (including Windows).
  • url.pathToFileURL('C:\\', { windows: true }).href and url.pathToFileURL('C:/', { windows: true }).href should return 'file:///C:/' on all platforms (including POSIX).
  • url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }) should throw ERR_INVALID_ARG_VALUE (Empty UNC servername), matching url.pathToFileURL('\\\\\\share', { windows: true }).
What do you see instead?
  • url.pathToFileURL('/', { windows: false }).href on Windows returns 'file:////'.
  • url.pathToFileURL('C:\\', { windows: true }).href on POSIX returns 'file:///C://'.
  • url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).href returns 'file:///share'.
Additional information

In lib/internal/url.js:

  • Line 1707 checks if (hostnameEndIndex === 2) instead of if (hostnameEndIndex === prefixLength).
  • Line 1722 checks resolved[resolved.length - 1] !== path.sep instead of resolved[resolved.length - 1] !== (windows ? '\\' : '/').
Vorherrschende Sprache
JavaScript
Sterne
123k
Forks
39.3k
Ø Merge
4 T. 11 Std.
Gemergte PRs (30 T.)
237

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus nodejs/node

Alle Issues in nodejs/node

Ähnliche Issues

Weitere Issues zu JavaScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.