|
@ -35,6 +35,7 @@ function normalizeStringWin32(path, allowAboveRoot) { |
|
|
var lastSlash = -1; |
|
|
var lastSlash = -1; |
|
|
var dots = 0; |
|
|
var dots = 0; |
|
|
var code; |
|
|
var code; |
|
|
|
|
|
var isAboveRoot = false; |
|
|
for (var i = 0; i <= path.length; ++i) { |
|
|
for (var i = 0; i <= path.length; ++i) { |
|
|
if (i < path.length) |
|
|
if (i < path.length) |
|
|
code = path.charCodeAt(i); |
|
|
code = path.charCodeAt(i); |
|
@ -46,7 +47,7 @@ function normalizeStringWin32(path, allowAboveRoot) { |
|
|
if (lastSlash === i - 1 || dots === 1) { |
|
|
if (lastSlash === i - 1 || dots === 1) { |
|
|
// NOOP
|
|
|
// NOOP
|
|
|
} else if (lastSlash !== i - 1 && dots === 2) { |
|
|
} 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 - 1) !== 46/*.*/ || |
|
|
res.charCodeAt(res.length - 2) !== 46/*.*/) { |
|
|
res.charCodeAt(res.length - 2) !== 46/*.*/) { |
|
|
if (res.length > 2) { |
|
|
if (res.length > 2) { |
|
@ -63,12 +64,14 @@ function normalizeStringWin32(path, allowAboveRoot) { |
|
|
res = res.slice(0, j); |
|
|
res = res.slice(0, j); |
|
|
lastSlash = i; |
|
|
lastSlash = i; |
|
|
dots = 0; |
|
|
dots = 0; |
|
|
|
|
|
isAboveRoot = false; |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
} else if (res.length === 2 || res.length === 1) { |
|
|
} else if (res.length === 2 || res.length === 1) { |
|
|
res = ''; |
|
|
res = ''; |
|
|
lastSlash = i; |
|
|
lastSlash = i; |
|
|
dots = 0; |
|
|
dots = 0; |
|
|
|
|
|
isAboveRoot = false; |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -77,12 +80,14 @@ function normalizeStringWin32(path, allowAboveRoot) { |
|
|
res += '\\..'; |
|
|
res += '\\..'; |
|
|
else |
|
|
else |
|
|
res = '..'; |
|
|
res = '..'; |
|
|
|
|
|
isAboveRoot = true; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (res.length > 0) |
|
|
if (res.length > 0) |
|
|
res += '\\' + path.slice(lastSlash + 1, i); |
|
|
res += '\\' + path.slice(lastSlash + 1, i); |
|
|
else |
|
|
else |
|
|
res = path.slice(lastSlash + 1, i); |
|
|
res = path.slice(lastSlash + 1, i); |
|
|
|
|
|
isAboveRoot = false; |
|
|
} |
|
|
} |
|
|
lastSlash = i; |
|
|
lastSlash = i; |
|
|
dots = 0; |
|
|
dots = 0; |
|
@ -101,6 +106,7 @@ function normalizeStringPosix(path, allowAboveRoot) { |
|
|
var lastSlash = -1; |
|
|
var lastSlash = -1; |
|
|
var dots = 0; |
|
|
var dots = 0; |
|
|
var code; |
|
|
var code; |
|
|
|
|
|
var isAboveRoot = false; |
|
|
for (var i = 0; i <= path.length; ++i) { |
|
|
for (var i = 0; i <= path.length; ++i) { |
|
|
if (i < path.length) |
|
|
if (i < path.length) |
|
|
code = path.charCodeAt(i); |
|
|
code = path.charCodeAt(i); |
|
@ -112,7 +118,7 @@ function normalizeStringPosix(path, allowAboveRoot) { |
|
|
if (lastSlash === i - 1 || dots === 1) { |
|
|
if (lastSlash === i - 1 || dots === 1) { |
|
|
// NOOP
|
|
|
// NOOP
|
|
|
} else if (lastSlash !== i - 1 && dots === 2) { |
|
|
} 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 - 1) !== 46/*.*/ || |
|
|
res.charCodeAt(res.length - 2) !== 46/*.*/) { |
|
|
res.charCodeAt(res.length - 2) !== 46/*.*/) { |
|
|
if (res.length > 2) { |
|
|
if (res.length > 2) { |
|
@ -129,12 +135,14 @@ function normalizeStringPosix(path, allowAboveRoot) { |
|
|
res = res.slice(0, j); |
|
|
res = res.slice(0, j); |
|
|
lastSlash = i; |
|
|
lastSlash = i; |
|
|
dots = 0; |
|
|
dots = 0; |
|
|
|
|
|
isAboveRoot = false; |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
} else if (res.length === 2 || res.length === 1) { |
|
|
} else if (res.length === 2 || res.length === 1) { |
|
|
res = ''; |
|
|
res = ''; |
|
|
lastSlash = i; |
|
|
lastSlash = i; |
|
|
dots = 0; |
|
|
dots = 0; |
|
|
|
|
|
isAboveRoot = false; |
|
|
continue; |
|
|
continue; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -143,12 +151,14 @@ function normalizeStringPosix(path, allowAboveRoot) { |
|
|
res += '/..'; |
|
|
res += '/..'; |
|
|
else |
|
|
else |
|
|
res = '..'; |
|
|
res = '..'; |
|
|
|
|
|
isAboveRoot = true; |
|
|
} |
|
|
} |
|
|
} else { |
|
|
} else { |
|
|
if (res.length > 0) |
|
|
if (res.length > 0) |
|
|
res += '/' + path.slice(lastSlash + 1, i); |
|
|
res += '/' + path.slice(lastSlash + 1, i); |
|
|
else |
|
|
else |
|
|
res = path.slice(lastSlash + 1, i); |
|
|
res = path.slice(lastSlash + 1, i); |
|
|
|
|
|
isAboveRoot = false; |
|
|
} |
|
|
} |
|
|
lastSlash = i; |
|
|
lastSlash = i; |
|
|
dots = 0; |
|
|
dots = 0; |
|
|