Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichaël Zasso <targos@protonmail.com>2017-07-06 18:14:16 +0300
committerMichaël Zasso <targos@protonmail.com>2017-08-30 15:44:55 +0300
commitb98e8d995efb426bbdee56ce503017bdcbbc6332 (patch)
tree44292dffa5e70a1484207677f47292a4b94b577e /lib/path.js
parent244ada3c71588f02c10c0fcc526863660d460c96 (diff)
path: fix normalize on directories with two dots
PR-URL: https://github.com/nodejs/node/pull/14107 Fixes: https://github.com/nodejs/node/issues/14105 Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'lib/path.js')
-rw-r--r--lib/path.js14
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/path.js b/lib/path.js
index 833daf7b461..24f6ed617f8 100644
--- a/lib/path.js
+++ b/lib/path.js
@@ -35,6 +35,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
var lastSlash = -1;
var dots = 0;
var code;
+ var isAboveRoot = false;
for (var i = 0; i <= path.length; ++i) {
if (i < path.length)
code = path.charCodeAt(i);
@@ -46,7 +47,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
- if (res.length < 2 ||
+ if (res.length < 2 || !isAboveRoot ||
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
res.charCodeAt(res.length - 2) !== 46/*.*/) {
if (res.length > 2) {
@@ -63,12 +64,14 @@ function normalizeStringWin32(path, allowAboveRoot) {
res = res.slice(0, j);
lastSlash = i;
dots = 0;
+ isAboveRoot = false;
continue;
}
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSlash = i;
dots = 0;
+ isAboveRoot = false;
continue;
}
}
@@ -77,12 +80,14 @@ function normalizeStringWin32(path, allowAboveRoot) {
res += '\\..';
else
res = '..';
+ isAboveRoot = true;
}
} else {
if (res.length > 0)
res += '\\' + path.slice(lastSlash + 1, i);
else
res = path.slice(lastSlash + 1, i);
+ isAboveRoot = false;
}
lastSlash = i;
dots = 0;
@@ -101,6 +106,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
var lastSlash = -1;
var dots = 0;
var code;
+ var isAboveRoot = false;
for (var i = 0; i <= path.length; ++i) {
if (i < path.length)
code = path.charCodeAt(i);
@@ -112,7 +118,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
if (lastSlash === i - 1 || dots === 1) {
// NOOP
} else if (lastSlash !== i - 1 && dots === 2) {
- if (res.length < 2 ||
+ if (res.length < 2 || !isAboveRoot ||
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
res.charCodeAt(res.length - 2) !== 46/*.*/) {
if (res.length > 2) {
@@ -129,12 +135,14 @@ function normalizeStringPosix(path, allowAboveRoot) {
res = res.slice(0, j);
lastSlash = i;
dots = 0;
+ isAboveRoot = false;
continue;
}
} else if (res.length === 2 || res.length === 1) {
res = '';
lastSlash = i;
dots = 0;
+ isAboveRoot = false;
continue;
}
}
@@ -143,12 +151,14 @@ function normalizeStringPosix(path, allowAboveRoot) {
res += '/..';
else
res = '..';
+ isAboveRoot = true;
}
} else {
if (res.length > 0)
res += '/' + path.slice(lastSlash + 1, i);
else
res = path.slice(lastSlash + 1, i);
+ isAboveRoot = false;
}
lastSlash = i;
dots = 0;