Repository navigation
url: fix case-insensitive extended UNC paths in pathToFileURL - #67178
Open
ShakilUrRehman21 wants to merge 1 commit into
Open
ShakilUrRehman21 wants to merge 1 commit into
ShakilUrRehman21 wants to merge 1 commit into
Conversation
Windows paths and namespaces are case-insensitive. Extended UNC paths prefixed with `\\?\unc\` or mixed case like `\\?\Unc\` were not recognized by `pathToFileURL` because it only checked for uppercase `\\?\UNC\`. As a result, the UNC prefix was incorrectly handled as a standard UNC path with an empty hostname, causing `fileURLToPath` to throw ERR_INVALID_FILE_URL_PATH on the resulting URL. Additionally, extended UNC paths with empty servernames (such as `\\?\UNC\\share`) were bypassing validation because the empty servername check was hardcoded to `hostnameEndIndex === 2` instead of checking against `prefixLength`. This commit updates `pathToFileURL` to: - Match `\\?\UNC\` case-insensitively using `StringPrototypeToUpperCase`. - Validate that `hostnameEndIndex !== prefixLength` before slicing the hostname, properly throwing ERR_INVALID_ARG_VALUE when the extended UNC servername is empty. - Add test coverage for lowercase and mixed-case extended UNC paths and empty extended UNC servernames. Signed-off-by: shakilurrehman21 <rehmanshakil21@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. |
4 tasks done
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.
Description
Windows paths and namespaces are case-insensitive. When using
url.pathToFileURL(), extended UNC paths prefixed with lowercase\\?\unc\or mixed-case\\?\Unc\were not recognized as extended UNC because the implementation strictly checked for uppercase'\\\\?\\UNC\\'.As a result:
"?"as the hostname."", swallowing the server name as a directory in the pathname (file:///unc/server/share/file.txt).fileURLToPath()threw a fatalTypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute.Additionally, extended UNC paths with empty servernames (e.g.
\\?\UNC\\shareor\\?\unc\\share) bypassed validation because the empty servername check was hardcoded tohostnameEndIndex === 2instead of checking againstprefixLength.This PR:
pathToFileURLto match\\?\UNC\case-insensitively usingStringPrototypeToUpperCase.hostnameEndIndex === prefixLength, properly throwingERR_INVALID_ARG_VALUEfor empty extended UNC servernames.Refs: #54262
Refs: #56302
Checklist
testpasses