path: fix normalize on directories with two dots · nodejs/node@f87a626
@@ -14,6 +14,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
1414var lastSlash = -1;
1515var dots = 0;
1616var code;
17+var isAboveRoot = false;
1718for (var i = 0; i <= path.length; ++i) {
1819if (i < path.length)
1920code = path.charCodeAt(i);
@@ -25,7 +26,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
2526if (lastSlash === i - 1 || dots === 1) {
2627// NOOP
2728} else if (lastSlash !== i - 1 && dots === 2) {
28-if (res.length < 2 ||
29+if (res.length < 2 || !isAboveRoot ||
2930res.charCodeAt(res.length - 1) !== 46/*.*/ ||
3031res.charCodeAt(res.length - 2) !== 46/*.*/) {
3132if (res.length > 2) {
@@ -42,12 +43,14 @@ function normalizeStringWin32(path, allowAboveRoot) {
4243res = res.slice(0, j);
4344lastSlash = i;
4445dots = 0;
46+isAboveRoot = false;
4547continue;
4648}
4749} else if (res.length === 2 || res.length === 1) {
4850res = '';
4951lastSlash = i;
5052dots = 0;
53+isAboveRoot = false;
5154continue;
5255}
5356}
@@ -56,12 +59,14 @@ function normalizeStringWin32(path, allowAboveRoot) {
5659res += '\\..';
5760else
5861res = '..';
62+isAboveRoot = true;
5963}
6064} else {
6165if (res.length > 0)
6266res += '\\' + path.slice(lastSlash + 1, i);
6367else
6468res = path.slice(lastSlash + 1, i);
69+isAboveRoot = false;
6570}
6671lastSlash = i;
6772dots = 0;
@@ -80,6 +85,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
8085var lastSlash = -1;
8186var dots = 0;
8287var code;
88+var isAboveRoot = false;
8389for (var i = 0; i <= path.length; ++i) {
8490if (i < path.length)
8591code = path.charCodeAt(i);
@@ -91,7 +97,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
9197if (lastSlash === i - 1 || dots === 1) {
9298// NOOP
9399} else if (lastSlash !== i - 1 && dots === 2) {
94-if (res.length < 2 ||
100+if (res.length < 2 || !isAboveRoot ||
95101res.charCodeAt(res.length - 1) !== 46/*.*/ ||
96102res.charCodeAt(res.length - 2) !== 46/*.*/) {
97103if (res.length > 2) {
@@ -108,12 +114,14 @@ function normalizeStringPosix(path, allowAboveRoot) {
108114res = res.slice(0, j);
109115lastSlash = i;
110116dots = 0;
117+isAboveRoot = false;
111118continue;
112119}
113120} else if (res.length === 2 || res.length === 1) {
114121res = '';
115122lastSlash = i;
116123dots = 0;
124+isAboveRoot = false;
117125continue;
118126}
119127}
@@ -122,12 +130,14 @@ function normalizeStringPosix(path, allowAboveRoot) {
122130res += '/..';
123131else
124132res = '..';
133+isAboveRoot = true;
125134}
126135} else {
127136if (res.length > 0)
128137res += '/' + path.slice(lastSlash + 1, i);
129138else
130139res = path.slice(lastSlash + 1, i);
140+isAboveRoot = false;
131141}
132142lastSlash = i;
133143dots = 0;