Skip to content

Unexpected path.join behaviour with windows drives #44063

Open
@Gershy

Description

@Gershy

Version

14.0.0

Platform

Microsoft Windows NT 10.0.19044.0 x64

Subsystem

No response

What steps will reproduce the bug?

I typically expect path.join(path.join(...paths1), ...paths2) === path.join(...paths1, ...paths2);

This is defied with:

let paths1 = [ 'C:' ];
let paths2 = [ 'abc' ];

Essentially because path.join('C:', 'abc') === 'C:\\abc';, I expect that path.join(path.join('C:'), 'abc') === 'C:\\abc';.

I also expect that if path.isAbsolute(myPath) is false, so too will path.isAbsolute(path.join(myPath, anotherPath)) be false. This can be summarized by saying "if a path is relative, a child path of that path is also relative", and seems like a very reasonable expectation - but it's defied when:

console.log( path.isAbsolute('C:') ); // false
console.log( path.isAbsolute(path.join('C:', 'abc')) ); // true

I also expect path.join(...cmps).split(path.sep) to give me a clone of cmps in most cases (specifically when cmps doesn't contain any .. or . components). This is defied when:

let cmps = [ 'C:' ];
console.log( path.join(...cmps).split(path.sep) ); // I expect [ 'C:' ], but get [ 'C:.' ] (note the "." character)

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

No context needed

What is the expected behavior?

assert(path.join(path.join('C:'), 'abc') === 'C:\\abc');
assert(path.isAbsolute('C:') === true);

let cmps = path.join('C:').split(path.sep);
assert(cmps.length === 1);
assert(cmps[0] === 'C:');

What do you see instead?

path.join(path.join('C:'), 'abc') === 'C:abc';
path.isAbsolute('C:') === false;
path.join('C:').split(path.sep)[0] === 'C:.';

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pathIssues and PRs related to the path subsystem.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