Skip to content

path.resolve not normalizing paths in Node 23 #55448

@steveluscher

Description

@steveluscher

Version

v23.0.0

Platform

Linux {HOSTNAME} 5.15.0-117-generic #127-Ubuntu SMP Fri Jul 5 20:13:28 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

Welcome to Node.js v23.0.0.
Type ".help" for more information.

require('path').resolve('/tmp/jest-changed-files-test-dir/nested-dir/second-nested-dir', '../../')
'/tmp/jest-changed-files-test-dir/'

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

Always.

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

The trailing slash should be stripped, as noted in the docs:

The resulting path is normalized and trailing slashes are removed unless the path is resolved to the root directory

Indeed the example in the docs themselves does not materialize in Node 23.

path.resolve('/foo/bar', '/tmp/file/');
// Returns: '/tmp/file'

It actually returns /tmp/file/.

What do you see instead?

The trailing slash is not stripped.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateIssues and PRs that are duplicates of other issues or PRs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions