Skip to content

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

@injunchoi98

Description

@injunchoi98

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.urlIssues and PRs related to the legacy built-in url module.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions