Skip to content

Incorrect normalization of POSIX paths with exactly two leading slashes #51345

Open
@jp-diegidio

Description

@jp-diegidio

Version

v20.10.0

Platform

Microsoft Windows NT 10.0.19045.0 x64

Subsystem

lib/path.js ("node:path/posix")

What steps will reproduce the bug?

When I normalize a POSIX path with 'node:path/posix', if the path contains exactly two leading slashes, I'd expect the two leading slashes NOT to be collapsed to one, as per the POSIX spec (see [1]), but the opposite appears to happen.

Here is an example with CMD on Win 10:

C:\Users\Julio>node
Welcome to Node.js v20.10.0.      
Type ".help" for more information.
> var $p = require("path/posix")
undefined
> $p.normalize("//alpha/beta")
'/alpha/beta'

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

Always.

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

Expected result is '//alpha/beta', i.e. the two leading slashes are NOT collapsed to one.

What do you see instead?

Actual result is '/alpha/beta', where the two leading slashes have been collapsed to one.

Additional information

[1] See POSIX.1-2017 / Base Definitions / 3.271 Pathname, which states:

Multiple successive slash characters are considered to be the same as one slash, except for the case of exactly two leading slash characters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    pathIssues and PRs related to the path subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions