Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

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

Fermée Adaptée aux débutants
#67,091 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@JoaoMarcos44 y travaille déjà.

Depuis le 28/10/2026.

  • #67092 par @JoaoMarcos44 — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
72/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
javascript, node.js
Domaine
api, backend

Piste de recherche

Commence dans lib/internal/url.js, aux deux emplacements indiqués dans l’issue, puis lis la logique de pathToFileURL() qui les entoure et les tests URL associés. Reproduis les cas de barre oblique racine avec { windows: false } et { windows: true }, et vérifie comment les tests existants couvrent les noms de serveur UNC étendus vides. Le travail est terminé lorsque les URL multiplateformes ont une seule barre oblique finale et que le nom de serveur vide déclenche ERR_INVALID_ARG_VALUE.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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 ? '\\' : '/').
Langage dominant
JavaScript
Étoiles
123k
Forks
39.3k
Merge moyen
4 j 12 h
PR mergées (30 j)
240

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de nodejs/node

Toutes les issues de nodejs/node

Issues similaires

Plus d'issues JavaScript

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.