Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8e7ac25
http, tls: better support for IPv6 addresses
mattiasholmlund Aug 10, 2017
e021fb7
doc,test: mention Duplex support for TLS
addaleax Dec 11, 2017
4879038
tools: add number-isnan rule
maclover7 Dec 11, 2017
969c39e
lib: enable dot-notation eslint rule
apapirovski Jan 5, 2018
16ef24b
test: use smaller input file for test-zlib.js
Trott Jan 5, 2018
17c88c4
doc: examples for fast-tracking regression fixes
refack Nov 26, 2017
37071b8
path: fix path.normalize for relative paths
starkwang Jan 4, 2018
838f7bd
doc: be less tentative about undefined behavior
Trott Jan 10, 2018
1505b71
doc: add Leko to collaborators
Leko Jan 11, 2018
8f9362d
doc: add documentation for deprecation properties
maclover7 Oct 26, 2017
2004efd
test: improve to use template string
sreepurnajasti Jan 10, 2018
eaa30e4
test: simplify loadDHParam in TLS test
tniessen Jan 11, 2018
df038ad
fs: fix options.end of fs.ReadStream()
Jan 12, 2018
2c21421
doc: simplify sentences that use "considered"
Trott Jan 11, 2018
2e76df5
doc: warn users about non-ASCII paths on build
Nov 4, 2017
b83b104
doc: add builtin module in building.md
Suixinlei Dec 16, 2017
46e4311
doc: V8 branch used in 8.x not active anymore
fhinkel Jan 15, 2018
1e8d120
doc: Add example of null to assert.ifError
Leko Jan 18, 2018
27107b9
test: use countdown timer
daxlab Nov 26, 2017
7fc5c69
doc: use PBKDF2 in text
tniessen Jan 21, 2018
bb2d292
test: change assert message to default
ryanmahan Jan 19, 2018
d333ba5
doc: add vdeturckheim as collaborator
vdeturckheim Jan 29, 2018
fdf73b1
test: preserve env in test cases
BethGriggs Aug 14, 2017
1246f72
2018-03-06, Version 6.13.1 'Boron' (LTS)
MylesBorins Feb 27, 2018
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
Prev Previous commit
Next Next commit
path: fix path.normalize for relative paths
After slicing, the `lastSegmentLength` should be calculated again,
instead of assigning value `j`.

PR-URL: #17974
Fixes: #17928
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information
starkwang authored and MylesBorins committed Feb 27, 2018
commit 37071b8ddae3c6c3b8cb544993deeb628cb678b4
30 changes: 10 additions & 20 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ function normalizeStringWin32(path, allowAboveRoot) {
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
res.charCodeAt(res.length - 2) !== 46/*.*/) {
if (res.length > 2) {
const start = res.length - 1;
var j = start;
for (; j >= 0; --j) {
if (res.charCodeAt(j) === 92/*\*/)
break;
}
if (j !== start) {
if (j === -1) {
const lastSlashIndex = res.lastIndexOf('\\');
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, j);
lastSegmentLength = j;
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf('\\');
}
lastSlash = i;
dots = 0;
Expand Down Expand Up @@ -103,19 +98,14 @@ function normalizeStringPosix(path, allowAboveRoot) {
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
res.charCodeAt(res.length - 2) !== 46/*.*/) {
if (res.length > 2) {
const start = res.length - 1;
var j = start;
for (; j >= 0; --j) {
if (res.charCodeAt(j) === 47/*/*/)
break;
}
if (j !== start) {
if (j === -1) {
const lastSlashIndex = res.lastIndexOf('/');
if (lastSlashIndex !== res.length - 1) {
if (lastSlashIndex === -1) {
res = '';
lastSegmentLength = 0;
} else {
res = res.slice(0, j);
lastSegmentLength = j;
res = res.slice(0, lastSlashIndex);
lastSegmentLength = res.length - 1 - res.lastIndexOf('/');
}
lastSlash = i;
dots = 0;
Expand Down
24 changes: 24 additions & 0 deletions test/parallel/test-path-normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ assert.strictEqual(path.win32.normalize('..\\foo..\\..\\..\\bar'),
'..\\..\\bar');
assert.strictEqual(path.win32.normalize('..\\...\\..\\.\\...\\..\\..\\bar'),
'..\\..\\bar');
assert.strictEqual(path.win32.normalize('../../../foo/../../../bar'),
'..\\..\\..\\..\\..\\bar');
assert.strictEqual(path.win32.normalize('../../../foo/../../../bar/../../'),
'..\\..\\..\\..\\..\\..\\');
assert.strictEqual(
path.win32.normalize('../foobar/barfoo/foo/../../../bar/../../'),
'..\\..\\'
);
assert.strictEqual(
path.win32.normalize('../.../../foobar/../../../bar/../../baz'),
'..\\..\\..\\..\\baz'
);

assert.strictEqual(path.posix.normalize('./fixtures///b/../b/c.js'),
'fixtures/b/c.js');
Expand All @@ -44,3 +56,15 @@ assert.strictEqual(path.posix.normalize('bar/foo..'), 'bar/foo..');
assert.strictEqual(path.posix.normalize('../foo../../../bar'), '../../bar');
assert.strictEqual(path.posix.normalize('../.../.././.../../../bar'),
'../../bar');
assert.strictEqual(path.posix.normalize('../../../foo/../../../bar'),
'../../../../../bar');
assert.strictEqual(path.posix.normalize('../../../foo/../../../bar/../../'),
'../../../../../../');
assert.strictEqual(
path.posix.normalize('../foobar/barfoo/foo/../../../bar/../../'),
'../../'
);
assert.strictEqual(
path.posix.normalize('../.../../foobar/../../../bar/../../baz'),
'../../../../baz'
);