Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d3b45a

Browse filesBrowse files
committed
path: fix normalize for absolutes
Fixes a regression introduced by b212be0. path.normalize(''/a/b/c/../../../x/y/z'') should return '/x/y/z'. Fixes: #5585 PR-URL: #5589 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
1 parent 1d9a2b2 commit 3d3b45a
Copy full SHA for 3d3b45a

File tree

Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+5
-2
lines changed
Open diff view settings
Collapse file

‎lib/path.js‎

Copy file name to clipboardExpand all lines: lib/path.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
4444
dots = 0;
4545
continue;
4646
}
47-
} else if (res.length === 2) {
47+
} else if (res.length === 2 || res.length === 1) {
4848
res = '';
4949
lastSlash = i;
5050
dots = 0;
@@ -110,7 +110,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
110110
dots = 0;
111111
continue;
112112
}
113-
} else if (res.length === 2) {
113+
} else if (res.length === 2 || res.length === 1) {
114114
res = '';
115115
lastSlash = i;
116116
dots = 0;
Collapse file

‎test/parallel/test-path.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-path.js
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,13 +377,16 @@ assert.equal(path.win32.normalize('a//b//./c'), 'a\\b\\c');
377377
assert.equal(path.win32.normalize('a//b//.'), 'a\\b');
378378
assert.equal(path.win32.normalize('//server/share/dir/file.ext'),
379379
'\\\\server\\share\\dir\\file.ext');
380+
assert.equal(path.win32.normalize('/a/b/c/../../../x/y/z'), '\\x\\y\\z');
380381

381382
assert.equal(path.posix.normalize('./fixtures///b/../b/c.js'),
382383
'fixtures/b/c.js');
383384
assert.equal(path.posix.normalize('/foo/../../../bar'), '/bar');
384385
assert.equal(path.posix.normalize('a//b//../b'), 'a/b');
385386
assert.equal(path.posix.normalize('a//b//./c'), 'a/b/c');
386387
assert.equal(path.posix.normalize('a//b//.'), 'a/b');
388+
assert.equal(path.posix.normalize('/a/b/c/../../../x/y/z'), '/x/y/z');
389+
assert.equal(path.posix.normalize('///..//./foo/.//bar'), '/foo/bar');
387390

388391

389392
// path.resolve tests

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.