Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathToFileURL function in url fails to handle \\?\UNC\ Prefix properly #54261

Closed
EarlyRiser42 opened this issue Aug 8, 2024 · 3 comments · Fixed by #54262
Closed

pathToFileURL function in url fails to handle \\?\UNC\ Prefix properly #54261

EarlyRiser42 opened this issue Aug 8, 2024 · 3 comments · Fixed by #54262
Labels
confirmed-bug Issues with confirmed bugs. url Issues and PRs related to the legacy built-in url module. windows Issues and PRs related to the Windows platform.

Comments

@EarlyRiser42
Copy link
Contributor

Version

22.5.1

Platform

Microsoft Windows NT 10.0.22631.0 x64

Subsystem

No response

What steps will reproduce the bug?

const { pathToFileURL } = require('url');

console.log(pathToFileURL('\\\\?\\UNC\\server\\share\\folder\\file.txt').href); 
// output: 'file:///UNC/server/share/folder/file.txt'

How often does it reproduce? Is there a required condition?

Anytime

What is the expected behavior? Why is that the expected behavior?

According to the Microsoft documentation on maximum file path limitations, the \?\UNC\ prefix are not used as part of the path itself. so it should be ignored when converting to a file URI. The current implementation does not adhere to this guideline, resulting in incorrect URL conversions. Its output should be file://server/share/folder/file.txt.

What do you see instead?

file:///UNC/server/share/folder/file.txt

Additional information

No response

@RedYetiDev RedYetiDev added url Issues and PRs related to the legacy built-in url module. windows Issues and PRs related to the Windows platform. repro-exists labels Aug 8, 2024
@RedYetiDev
Copy link
Member

RedYetiDev commented Aug 8, 2024

Reproduction:

$ node
Welcome to Node.js v22.5.1.
Type ".help" for more information.
> require('url').pathToFileURL('\\\\?\\UNC\\server\\share\\folder\\file.txt', { windows: false }).href;
'file:///<path>/%5C%5C%3F%5CUNC%5Cserver%5Cshare%5Cfolder%5Cfile.txt'
> require('url').pathToFileURL('\\\\?\\UNC\\server\\share\\folder\\file.txt', { windows: true }).href;
'file:///UNC/server/share/folder/file.txt'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. url Issues and PRs related to the legacy built-in url module. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@aduh95 @RedYetiDev @EarlyRiser42 and others