Repository navigation
url: fix extra slash on file URL roots - #67955
Open
jaideeppyne wants to merge 1 commit into
Open
jaideeppyne wants to merge 1 commit into
jaideeppyne wants to merge 1 commit into
Conversation
pathToFileURL() restores a trailing separator by comparing the
resolved path with path.sep. That is the host separator, so it
disagrees with options.windows. "C:\" on a POSIX host was encoded
as file:///C://, and "/" on a Windows host with { windows: false }
as file:////. Compare against the separator for the selected
platform instead.
Refs: nodejs#67091
Signed-off-by: jaideeppyne <jaideeppyne1997@gmail.com>
Collaborator
|
Review requested:
|
Contributor
|
Welcome to Node.js, and thank you for your first contribution! Before review, please take a moment to read:
Please make sure every commit is signed off. For a first pull request, GitHub Actions require collaborator approval and Jenkins CI must be started by a collaborator or triager, so an initial wait is normal. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
pathToFileURL()puts back a trailing slash thatpath.resolve()drops for non-root paths, but it compared the resolved path withpath.sep. That is the host separator, not the separator selected byoptions.windows.On a POSIX host,
pathToFileURL('C:\\', { windows: true })appended an extra slash and returnedfile:///C://. The same input with a resolved root that did not go through that append (C:\\.) already returnedfile:///C:/. On a Windows host,pathToFileURL('/', { windows: false })returnedfile:////. A root already ends in the selected platform's separator, so it must not gain another one. Other directories still keep a single trailing slash.The new test fails on current main (
file:///C://) and passes with this change.test/parallel/test-url-pathtofileurl.jsstill passes.Refs: #67091
A closed-source coding agent helped locate this bug and draft the patch. I read
pathToFileURLinlib/internal/url.js, reproducedpathToFileURL('C:\\', { windows: true }).href === 'file:///C://'on Node.js v26.7.0, and ran the new test on a binary built from this tree with--node-builtin-modules-path: it failed on unmodified main and passed after this change. The existingpathToFileURLtest passed on that binary as well.