Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Fechada Para iniciantes
#67,091 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@JoaoMarcos44 já está trabalhando nisso.

Desde 28/10/2026.

  • #67092 de @JoaoMarcos44 — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
72/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
javascript, node.js
Domínio
api, backend

Direção de pesquisa

Comece em lib/internal/url.js, nos dois locais identificados na issue, e depois leia a lógica de pathToFileURL() ao redor e os testes de URL relacionados. Reproduza os casos de barra raiz com { windows: false } e { windows: true } e verifique como os testes existentes cobrem nomes de servidor UNC estendidos vazios. O trabalho estará concluído quando as URLs multiplataforma tiverem uma única barra no final e o nome de servidor vazio lançar ERR_INVALID_ARG_VALUE.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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 ? '\\' : '/').
Linguagem predominante
JavaScript
Estrelas
123k
Forks
39.3k
Merge médio
4d 12h
PRs com merge (30d)
240

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de nodejs/node

Todas as issues de nodejs/node

Issues semelhantes

Mais issues de JavaScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.