Skip to content

path.relative adds trailing slash in node 12 #28549

@dominikwilkowski

Description

@dominikwilkowski

What happens in node < 12

const Path = require('path');
Path.relative('/page1/page2/foo', '/');
// '../../..'
Path.relative('/page1/page2/foo', '/page1/');
// '../..'
Path.relative('/page1/page2/foo', '/page1/page2/');
// '..'

What happens in node => 12

const Path = require('path');
Path.relative('/page1/page2/foo', '/');
// '../../../'
//          ^--- Note the trailing slash
Path.relative('/page1/page2/foo', '/page1/');
// '../..'
Path.relative('/page1/page2/foo', '/page1/page2/');
// '..'

Note the inconsistency when resolving a path against root. In node 12 we now get a trailing slash.

What I expect should happen

We either resolve all paths with or without trailing slashes but not mix both.
Nodes behavior prior to 12 was more consistent.

  • 12.6.0
  • OSX 10.14.5

Metadata

Metadata

Assignees

Labels

confirmed-bugIssues with confirmed bugs.pathIssues and PRs related to the path subsystem.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions