nodejs / nodejs/node

ToNamespacedPath doesn't work with device names

Open
#54,180 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

path windows
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

v20.16.0

Platform
Microsoft Windows NT 10.0.22635.0 x64
Subsystem

No response

What steps will reproduce the bug?
import path from 'node:path'
console.log(path.toNamespacedPath("COM3"))
How often does it reproduce? Is there a required condition?

Every time.

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

This should print:

\\.\COM3

which is the fully qualified path in the device namespace

What do you see instead?

This prints the illegal path:

\\?\C:\Users\dan\COM3
Additional information

Reference for legal path name: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#win32-device-namespaces
Additionally console.log(url.pathToFileURL("COM3").href) prints an invalid URL, but I'm not sure if there is a corresponding valid file: URL.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the node:path toNamespacedPath("COM3") reproduction on Windows and compare it with the expected device-namespace path \.\COM3. Check the related url.pathToFileURL("COM3") behavior as additional context; done means the path API returns the legal device path without breaking normal paths.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
backend, operating-systems
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.