Skip to content

url: fix case-insensitive extended UNC paths in pathToFileURL - #67178

Open
ShakilUrRehman21 wants to merge 1 commit into
nodejs:mainfrom
ShakilUrRehman21:url-fix-extended-unc-path-handling
Open

ShakilUrRehman21 wants to merge 1 commit into
nodejs:mainfrom
ShakilUrRehman21:url-fix-extended-unc-path-handling

Conversation

@ShakilUrRehman21

Copy link
Copy Markdown

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:

  • The path was parsed as a standard UNC path with prefix length 2, extracting "?" as the hostname.
  • Ada / WHATWG URL parser stripped the invalid hostname to empty "", swallowing the server name as a directory in the pathname (file:///unc/server/share/file.txt).
  • Passing the resulting URL to fileURLToPath() threw a fatal TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute.

Additionally, extended UNC paths with empty servernames (e.g. \\?\UNC\\share or \\?\unc\\share) bypassed validation because the empty servername check was hardcoded to hostnameEndIndex === 2 instead of checking against prefixLength.

This PR:

  1. Updates pathToFileURL to match \\?\UNC\ case-insensitively using StringPrototypeToUpperCase.
  2. Updates the empty servername check to hostnameEndIndex === prefixLength, properly throwing ERR_INVALID_ARG_VALUE for empty extended UNC servernames.
  3. Adds test coverage for lowercase and mixed-case extended UNC paths, as well as empty extended UNC servernames and missing resource paths.

Refs: #54262
Refs: #56302

Checklist

  • test passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

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>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/url

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants