url: pathToFileURL duplicates root slash across platforms and misses empty extended UNC servername
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript, node.js
Direzione di ricerca
Inizia in lib/internal/url.js, nei due punti indicati nell’issue, poi leggi la logica circostante di pathToFileURL() e i test URL correlati. Riproduci i casi con slash radice usando { windows: false } e { windows: true } e verifica come i test esistenti coprono i nomi di server UNC estesi vuoti. Il lavoro è completato quando gli URL multipiattaforma hanno un solo slash finale e il nome del server vuoto genera ERR_INVALID_ARG_VALUE.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
-
Cross-platform root path trailing slash duplication (
resolved[resolved.length - 1] !== path.sep):
When restoring trailing slashes stripped bypath.resolve(),pathToFileURL()compares the last character ofresolvedagainst the host platform'spath.sepinstead 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:/') -
Extended UNC path empty servername bypass (
hostnameEndIndex === 2):
For extended UNC paths (\\?\UNC\...),prefixLengthis8, but the empty servername check hardcodesif (hostnameEndIndex === 2)instead ofif (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 }).hrefshould return'file:///'on all platforms (including Windows).url.pathToFileURL('C:\\', { windows: true }).hrefandurl.pathToFileURL('C:/', { windows: true }).hrefshould return'file:///C:/'on all platforms (including POSIX).url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true })should throwERR_INVALID_ARG_VALUE(Empty UNC servername), matchingurl.pathToFileURL('\\\\\\share', { windows: true }).
What do you see instead?
url.pathToFileURL('/', { windows: false }).hrefon Windows returns'file:////'.url.pathToFileURL('C:\\', { windows: true }).hrefon POSIX returns'file:///C://'.url.pathToFileURL('\\\\?\\UNC\\\\share', { windows: true }).hrefreturns'file:///share'.
Additional information
In lib/internal/url.js:
- Line 1707 checks
if (hostnameEndIndex === 2)instead ofif (hostnameEndIndex === prefixLength). - Line 1722 checks
resolved[resolved.length - 1] !== path.sepinstead ofresolved[resolved.length - 1] !== (windows ? '\\' : '/').
- Lingua principale
- JavaScript
- Stelle
- 123k
- Fork
- 39.3k
- Merge medio
- 4g 16h
- PR unite (30g)
- 227
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nodejs/node
-
http2: content-encoding is incorrectly listed in kSingleValueHeadersForse già presa @inoway46 l’ha presa 1 giorno fa. Apertaconfirmed-bug http2
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
nodejs/node#67151 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
util.parseEnv and --env-file keep a leading UTF-8 BOM in the first keyForse già presa @helmipradita l’ha presa 3 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
node:internal/inspector/network_http: `TypeError: Missing dataLength` in event when response uses `setEncoding()`Forse di nuovo libera Una pull request per questa issue è stata chiusa senza essere unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
nodejs/node#66551 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[Docs] `process.loadEnvFile()` does not document behaviour when variables already existForse già presa @Sepandard l’ha presa 37 giorni fa. Apertadoc
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
I maintainer di solito rispondono entro 1 giorno
-
Stream.prototype.forEach will block in first promise in queue before read more chunkForse già presa @mmustafasenoglu l’ha presa 37 giorni fa. Apertadoc
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
Site Suggestion: bullseyeAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 65/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
I maintainer di solito rispondono entro 25 giorni
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
libnativeapi/nativeapi#21 ·
-
area: core complexity: easy impact: medium
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
ueberdosis/tiptap#8668 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno