path: fix normalize for absolutes
Fixes a regression introduced by b212be08f62a48656c5befd8be0a82d691ea66e4. path.normalize(''/a/b/c/../../../x/y/z'') should return '/x/y/z'. Fixes: https://github.com/nodejs/node/issues/5585 PR-URL: https://github.com/nodejs/node/pull/5589 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
This commit is contained in:
parent
1d9a2b28bb
commit
3d3b45ae95
@ -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;
|
||||
@ -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;
|
||||
|
@ -377,6 +377,7 @@ 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');
|
||||
@ -384,6 +385,8 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user