Skip to content

On Windows, node inconsistently capitalizes drive letters when resolving junctions #38459

Description

@xirzec
  • Version: v14.16.0
  • Platform: Microsoft Windows NT 10.0.19042.0 x64
  • Subsystem: fs

What steps will reproduce the bug?

Create a small repro directory that contains a junction from one folder to another and create a simple source file:

mkdir C:\repro-realpath-bug
mkdir C:\repro-realpath-bug\src
mklink /J "C:\repro-realpath-bug\link" "C:\repro-realpath-bug\src"
echo console.log('hello world!'); >> "C:\repro-realpath-bug\src\index.js"

Now enter the directory and try using realpath:

cd c:\repro-realpath-bug
node
> fs.realpathSync("./src/index.js")
'c:\\repro-realpath-bug\\src\\index.js'
> fs.realpathSync("./link/index.js")
'C:\\repro-realpath-bug\\src\\index.js'

Notice the link drive letter is capitalized (as the junction target drive letter is capitalized) but targeting the file directly gives us a lowercased drive letter (that matches the cd command target).

If you do cd C:\repro-realpath-bug however, they will match.

What is the expected behavior?

Regardless of the path to get to the real file, the drive letter casing matches what is in process.cwd(), like when following a relative path.

What do you see instead?

When following a junction, the path casing changes to whatever the junction target uses

Additional information

Note that this bug works the other way too, if you create the junction with a lowercase drive letter

mklink /J "c:\repro-realpath-bug\link2" "c:\repro-realpath-bug\src"
C:\repro-realpath-bug> node
> fs.realpathSync("./link2/index.js")
'c:\\repro-realpath-bug\\src\\index.js'

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.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