Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
  • Loading branch information
evanlucas committed Mar 7, 2016
commit 3d3b45ae958f5bfc8cfdbdb30bcfd512a18740af
4 changes: 2 additions & 2 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
dots = 0;
continue;
}
} else if (res.length === 2) {
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSlash = i;
dots = 0;
Expand Down Expand Up @@ -110,7 +110,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
dots = 0;
continue;
}
} else if (res.length === 2) {
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSlash = i;
dots = 0;
Expand Down
3 changes: 3 additions & 0 deletions test/parallel/test-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,16 @@ assert.equal(path.win32.normalize('a//b//./c'), 'a\\b\\c');
assert.equal(path.win32.normalize('a//b//.'), 'a\\b');
assert.equal(path.win32.normalize('//server/share/dir/file.ext'),
'\\\\server\\share\\dir\\file.ext');
assert.equal(path.win32.normalize('/a/b/c/../../../x/y/z'), '\\x\\y\\z');

assert.equal(path.posix.normalize('./fixtures///b/../b/c.js'),
'fixtures/b/c.js');
assert.equal(path.posix.normalize('/foo/../../../bar'), '/bar');
assert.equal(path.posix.normalize('a//b//../b'), 'a/b');
assert.equal(path.posix.normalize('a//b//./c'), 'a/b/c');
assert.equal(path.posix.normalize('a//b//.'), 'a/b');
assert.equal(path.posix.normalize('/a/b/c/../../../x/y/z'), '/x/y/z');
assert.equal(path.posix.normalize('///..//./foo/.//bar'), '/foo/bar');


// path.resolve tests
Expand Down