Skip to content

Commit 3d3b45a

Browse 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 <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Brian White <[email protected]>
1 parent 1d9a2b2 commit 3d3b45a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

lib/path.js

+2-2
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;

test/parallel/test-path.js

+3
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)