Skip to content

url.pathToFileURL generates an incorrect file URL if the cwd is a UNC path. #56262

@Jason3S

Description

@Jason3S

Version

18, 20, 22, 23.4.0

Platform

Microsoft Windows NT 10.0.22631.0 x64

Subsystem

No response

What steps will reproduce the bug?

PowerShell

I have a machine called strongman.

Setup

cd \\strongman\c$\Users
node

REPL

> process.cwd() // make sure it is a UNC path
'\\\\strongman\\c$\\Users'
> url.pathToFileURL('.')
URL {
  href: 'file:////strongman/c$/Users',
  origin: 'null',
  protocol: 'file:',
  username: '',
  password: '',
  host: '',
  hostname: '',
  port: '',
  pathname: '//strongman/c$/Users',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}

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

100% of the time.

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

url.pathToFileURL('.') should create the correct URL: file://hostname/c$/Users.

What do you see instead?

url.pathToFileURL('.') creates a URL of the form: file:////hostname/c$/Users.

Additional information

Related to #56261 and #34736

Metadata

Metadata

Assignees

No one assigned

    Labels

    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