path: replace "magic" numbers by readable constants
PR-URL: https://github.com/nodejs/node/pull/18654 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
parent
3d53848d75
commit
6abce37f34
16
lib/internal/constants.js
Normal file
16
lib/internal/constants.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
// Alphabet chars.
|
||||||
|
CHAR_UPPERCASE_A: 65, /*A*/
|
||||||
|
CHAR_LOWERCASE_A: 97, /*a*/
|
||||||
|
CHAR_UPPERCASE_Z: 90, /*Z*/
|
||||||
|
CHAR_LOWERCASE_Z: 122, /*z*/
|
||||||
|
|
||||||
|
// Non-alphabetic chars.
|
||||||
|
CHAR_DOT: 46, /*.*/
|
||||||
|
CHAR_FORWARD_SLASH: 47, /*/*/
|
||||||
|
CHAR_BACKWARD_SLASH: 92, /*\*/
|
||||||
|
CHAR_COLON: 58, /*:*/
|
||||||
|
CHAR_QUESTION_MARK: 63, /*?*/
|
||||||
|
};
|
238
lib/path.js
238
lib/path.js
@ -22,6 +22,17 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const errors = require('internal/errors');
|
const errors = require('internal/errors');
|
||||||
|
const {
|
||||||
|
CHAR_UPPERCASE_A,
|
||||||
|
CHAR_LOWERCASE_A,
|
||||||
|
CHAR_UPPERCASE_Z,
|
||||||
|
CHAR_LOWERCASE_Z,
|
||||||
|
CHAR_DOT,
|
||||||
|
CHAR_FORWARD_SLASH,
|
||||||
|
CHAR_BACKWARD_SLASH,
|
||||||
|
CHAR_COLON,
|
||||||
|
CHAR_QUESTION_MARK,
|
||||||
|
} = require('internal/constants');
|
||||||
|
|
||||||
function assertPath(path) {
|
function assertPath(path) {
|
||||||
if (typeof path !== 'string') {
|
if (typeof path !== 'string') {
|
||||||
@ -39,17 +50,17 @@ function normalizeStringWin32(path, allowAboveRoot) {
|
|||||||
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);
|
||||||
else if (code === 47/*/*/ || code === 92/*\*/)
|
else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
code = 47/*/*/;
|
code = CHAR_FORWARD_SLASH;
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
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 || lastSegmentLength !== 2 ||
|
if (res.length < 2 || lastSegmentLength !== 2 ||
|
||||||
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
|
res.charCodeAt(res.length - 1) !== CHAR_DOT ||
|
||||||
res.charCodeAt(res.length - 2) !== 46/*.*/) {
|
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
|
||||||
if (res.length > 2) {
|
if (res.length > 2) {
|
||||||
const lastSlashIndex = res.lastIndexOf('\\');
|
const lastSlashIndex = res.lastIndexOf('\\');
|
||||||
if (lastSlashIndex !== res.length - 1) {
|
if (lastSlashIndex !== res.length - 1) {
|
||||||
@ -88,7 +99,7 @@ function normalizeStringWin32(path, allowAboveRoot) {
|
|||||||
}
|
}
|
||||||
lastSlash = i;
|
lastSlash = i;
|
||||||
dots = 0;
|
dots = 0;
|
||||||
} else if (code === 46/*.*/ && dots !== -1) {
|
} else if (code === CHAR_DOT && dots !== -1) {
|
||||||
++dots;
|
++dots;
|
||||||
} else {
|
} else {
|
||||||
dots = -1;
|
dots = -1;
|
||||||
@ -107,17 +118,17 @@ function normalizeStringPosix(path, allowAboveRoot) {
|
|||||||
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);
|
||||||
else if (code === 47/*/*/)
|
else if (code === CHAR_FORWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
code = 47/*/*/;
|
code = CHAR_FORWARD_SLASH;
|
||||||
if (code === 47/*/*/) {
|
if (code === CHAR_FORWARD_SLASH) {
|
||||||
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 || lastSegmentLength !== 2 ||
|
if (res.length < 2 || lastSegmentLength !== 2 ||
|
||||||
res.charCodeAt(res.length - 1) !== 46/*.*/ ||
|
res.charCodeAt(res.length - 1) !== CHAR_DOT ||
|
||||||
res.charCodeAt(res.length - 2) !== 46/*.*/) {
|
res.charCodeAt(res.length - 2) !== CHAR_DOT) {
|
||||||
if (res.length > 2) {
|
if (res.length > 2) {
|
||||||
const lastSlashIndex = res.lastIndexOf('/');
|
const lastSlashIndex = res.lastIndexOf('/');
|
||||||
if (lastSlashIndex !== res.length - 1) {
|
if (lastSlashIndex !== res.length - 1) {
|
||||||
@ -156,7 +167,7 @@ function normalizeStringPosix(path, allowAboveRoot) {
|
|||||||
}
|
}
|
||||||
lastSlash = i;
|
lastSlash = i;
|
||||||
dots = 0;
|
dots = 0;
|
||||||
} else if (code === 46/*.*/ && dots !== -1) {
|
} else if (code === CHAR_DOT && dots !== -1) {
|
||||||
++dots;
|
++dots;
|
||||||
} else {
|
} else {
|
||||||
dots = -1;
|
dots = -1;
|
||||||
@ -223,7 +234,7 @@ const win32 = {
|
|||||||
|
|
||||||
// Try to match a root
|
// Try to match a root
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Possible UNC root
|
// Possible UNC root
|
||||||
|
|
||||||
// If we started with a separator, we know we at least have an
|
// If we started with a separator, we know we at least have an
|
||||||
@ -231,14 +242,14 @@ const win32 = {
|
|||||||
isAbsolute = true;
|
isAbsolute = true;
|
||||||
|
|
||||||
code = path.charCodeAt(1);
|
code = path.charCodeAt(1);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Matched double path separator at beginning
|
// Matched double path separator at beginning
|
||||||
var j = 2;
|
var j = 2;
|
||||||
var last = j;
|
var last = j;
|
||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -248,7 +259,7 @@ const win32 = {
|
|||||||
// Match 1 or more path separators
|
// Match 1 or more path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code !== 47/*/*/ && code !== 92/*\*/)
|
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -257,7 +268,10 @@ const win32 = {
|
|||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
const isPathSeparator =
|
||||||
|
code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
|
||||||
|
|
||||||
|
if (isPathSeparator)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j === len) {
|
if (j === len) {
|
||||||
@ -276,16 +290,16 @@ const win32 = {
|
|||||||
} else {
|
} else {
|
||||||
rootEnd = 1;
|
rootEnd = 1;
|
||||||
}
|
}
|
||||||
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
|
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
|
||||||
(code >= 97/*a*/ && code <= 122/*z*/)) {
|
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
|
||||||
// Possible device root
|
// Possible device root
|
||||||
|
|
||||||
if (path.charCodeAt(1) === 58/*:*/) {
|
if (path.charCodeAt(1) === CHAR_COLON) {
|
||||||
device = path.slice(0, 2);
|
device = path.slice(0, 2);
|
||||||
rootEnd = 2;
|
rootEnd = 2;
|
||||||
if (len > 2) {
|
if (len > 2) {
|
||||||
code = path.charCodeAt(2);
|
code = path.charCodeAt(2);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Treat separator following drive name as an absolute path
|
// Treat separator following drive name as an absolute path
|
||||||
// indicator
|
// indicator
|
||||||
isAbsolute = true;
|
isAbsolute = true;
|
||||||
@ -294,7 +308,7 @@ const win32 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// `path` contains just a path separator
|
// `path` contains just a path separator
|
||||||
rootEnd = 1;
|
rootEnd = 1;
|
||||||
isAbsolute = true;
|
isAbsolute = true;
|
||||||
@ -343,7 +357,7 @@ const win32 = {
|
|||||||
|
|
||||||
// Try to match a root
|
// Try to match a root
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Possible UNC root
|
// Possible UNC root
|
||||||
|
|
||||||
// If we started with a separator, we know we at least have an absolute
|
// If we started with a separator, we know we at least have an absolute
|
||||||
@ -351,14 +365,14 @@ const win32 = {
|
|||||||
isAbsolute = true;
|
isAbsolute = true;
|
||||||
|
|
||||||
code = path.charCodeAt(1);
|
code = path.charCodeAt(1);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Matched double path separator at beginning
|
// Matched double path separator at beginning
|
||||||
var j = 2;
|
var j = 2;
|
||||||
var last = j;
|
var last = j;
|
||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -368,7 +382,7 @@ const win32 = {
|
|||||||
// Match 1 or more path separators
|
// Match 1 or more path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code !== 47/*/*/ && code !== 92/*\*/)
|
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -377,7 +391,7 @@ const win32 = {
|
|||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j === len) {
|
if (j === len) {
|
||||||
@ -397,16 +411,16 @@ const win32 = {
|
|||||||
} else {
|
} else {
|
||||||
rootEnd = 1;
|
rootEnd = 1;
|
||||||
}
|
}
|
||||||
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
|
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
|
||||||
(code >= 97/*a*/ && code <= 122/*z*/)) {
|
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
|
||||||
// Possible device root
|
// Possible device root
|
||||||
|
|
||||||
if (path.charCodeAt(1) === 58/*:*/) {
|
if (path.charCodeAt(1) === CHAR_COLON) {
|
||||||
device = path.slice(0, 2);
|
device = path.slice(0, 2);
|
||||||
rootEnd = 2;
|
rootEnd = 2;
|
||||||
if (len > 2) {
|
if (len > 2) {
|
||||||
code = path.charCodeAt(2);
|
code = path.charCodeAt(2);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Treat separator following drive name as an absolute path
|
// Treat separator following drive name as an absolute path
|
||||||
// indicator
|
// indicator
|
||||||
isAbsolute = true;
|
isAbsolute = true;
|
||||||
@ -415,14 +429,15 @@ const win32 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// `path` contains just a path separator, exit early to avoid unnecessary
|
// `path` contains just a path separator, exit early to avoid unnecessary
|
||||||
// work
|
// work
|
||||||
return '\\';
|
return '\\';
|
||||||
}
|
}
|
||||||
|
|
||||||
code = path.charCodeAt(len - 1);
|
code = path.charCodeAt(len - 1);
|
||||||
var trailingSeparator = (code === 47/*/*/ || code === 92/*\*/);
|
var trailingSeparator =
|
||||||
|
(code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH);
|
||||||
var tail;
|
var tail;
|
||||||
if (rootEnd < len)
|
if (rootEnd < len)
|
||||||
tail = normalizeStringWin32(path.slice(rootEnd), !isAbsolute);
|
tail = normalizeStringWin32(path.slice(rootEnd), !isAbsolute);
|
||||||
@ -462,15 +477,15 @@ const win32 = {
|
|||||||
if (len === 0)
|
if (len === 0)
|
||||||
return false;
|
return false;
|
||||||
var code = path.charCodeAt(0);
|
var code = path.charCodeAt(0);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
return true;
|
return true;
|
||||||
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
|
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
|
||||||
(code >= 97/*a*/ && code <= 122/*z*/)) {
|
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
|
||||||
// Possible device root
|
// Possible device root
|
||||||
|
|
||||||
if (len > 2 && path.charCodeAt(1) === 58/*:*/) {
|
if (len > 2 && path.charCodeAt(1) === CHAR_COLON) {
|
||||||
code = path.charCodeAt(2);
|
code = path.charCodeAt(2);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -514,16 +529,16 @@ const win32 = {
|
|||||||
var needsReplace = true;
|
var needsReplace = true;
|
||||||
var slashCount = 0;
|
var slashCount = 0;
|
||||||
var code = firstPart.charCodeAt(0);
|
var code = firstPart.charCodeAt(0);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
++slashCount;
|
++slashCount;
|
||||||
const firstLen = firstPart.length;
|
const firstLen = firstPart.length;
|
||||||
if (firstLen > 1) {
|
if (firstLen > 1) {
|
||||||
code = firstPart.charCodeAt(1);
|
code = firstPart.charCodeAt(1);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
++slashCount;
|
++slashCount;
|
||||||
if (firstLen > 2) {
|
if (firstLen > 2) {
|
||||||
code = firstPart.charCodeAt(2);
|
code = firstPart.charCodeAt(2);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
++slashCount;
|
++slashCount;
|
||||||
else {
|
else {
|
||||||
// We matched a UNC path in the first part
|
// We matched a UNC path in the first part
|
||||||
@ -537,7 +552,7 @@ const win32 = {
|
|||||||
// Find any more consecutive slashes we need to replace
|
// Find any more consecutive slashes we need to replace
|
||||||
for (; slashCount < joined.length; ++slashCount) {
|
for (; slashCount < joined.length; ++slashCount) {
|
||||||
code = joined.charCodeAt(slashCount);
|
code = joined.charCodeAt(slashCount);
|
||||||
if (code !== 47/*/*/ && code !== 92/*\*/)
|
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,13 +591,13 @@ const win32 = {
|
|||||||
// Trim any leading backslashes
|
// Trim any leading backslashes
|
||||||
var fromStart = 0;
|
var fromStart = 0;
|
||||||
for (; fromStart < from.length; ++fromStart) {
|
for (; fromStart < from.length; ++fromStart) {
|
||||||
if (from.charCodeAt(fromStart) !== 92/*\*/)
|
if (from.charCodeAt(fromStart) !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Trim trailing backslashes (applicable to UNC paths only)
|
// Trim trailing backslashes (applicable to UNC paths only)
|
||||||
var fromEnd = from.length;
|
var fromEnd = from.length;
|
||||||
for (; fromEnd - 1 > fromStart; --fromEnd) {
|
for (; fromEnd - 1 > fromStart; --fromEnd) {
|
||||||
if (from.charCodeAt(fromEnd - 1) !== 92/*\*/)
|
if (from.charCodeAt(fromEnd - 1) !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var fromLen = (fromEnd - fromStart);
|
var fromLen = (fromEnd - fromStart);
|
||||||
@ -590,13 +605,13 @@ const win32 = {
|
|||||||
// Trim any leading backslashes
|
// Trim any leading backslashes
|
||||||
var toStart = 0;
|
var toStart = 0;
|
||||||
for (; toStart < to.length; ++toStart) {
|
for (; toStart < to.length; ++toStart) {
|
||||||
if (to.charCodeAt(toStart) !== 92/*\*/)
|
if (to.charCodeAt(toStart) !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Trim trailing backslashes (applicable to UNC paths only)
|
// Trim trailing backslashes (applicable to UNC paths only)
|
||||||
var toEnd = to.length;
|
var toEnd = to.length;
|
||||||
for (; toEnd - 1 > toStart; --toEnd) {
|
for (; toEnd - 1 > toStart; --toEnd) {
|
||||||
if (to.charCodeAt(toEnd - 1) !== 92/*\*/)
|
if (to.charCodeAt(toEnd - 1) !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var toLen = (toEnd - toStart);
|
var toLen = (toEnd - toStart);
|
||||||
@ -608,7 +623,7 @@ const win32 = {
|
|||||||
for (; i <= length; ++i) {
|
for (; i <= length; ++i) {
|
||||||
if (i === length) {
|
if (i === length) {
|
||||||
if (toLen > length) {
|
if (toLen > length) {
|
||||||
if (to.charCodeAt(toStart + i) === 92/*\*/) {
|
if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
|
||||||
// We get here if `from` is the exact base path for `to`.
|
// We get here if `from` is the exact base path for `to`.
|
||||||
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
|
// For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
|
||||||
return toOrig.slice(toStart + i + 1);
|
return toOrig.slice(toStart + i + 1);
|
||||||
@ -619,7 +634,7 @@ const win32 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (fromLen > length) {
|
if (fromLen > length) {
|
||||||
if (from.charCodeAt(fromStart + i) === 92/*\*/) {
|
if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
|
||||||
// We get here if `to` is the exact base path for `from`.
|
// We get here if `to` is the exact base path for `from`.
|
||||||
// For example: from='C:\\foo\\bar'; to='C:\\foo'
|
// For example: from='C:\\foo\\bar'; to='C:\\foo'
|
||||||
lastCommonSep = i;
|
lastCommonSep = i;
|
||||||
@ -635,7 +650,7 @@ const win32 = {
|
|||||||
var toCode = to.charCodeAt(toStart + i);
|
var toCode = to.charCodeAt(toStart + i);
|
||||||
if (fromCode !== toCode)
|
if (fromCode !== toCode)
|
||||||
break;
|
break;
|
||||||
else if (fromCode === 92/*\*/)
|
else if (fromCode === CHAR_BACKWARD_SLASH)
|
||||||
lastCommonSep = i;
|
lastCommonSep = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -651,7 +666,7 @@ const win32 = {
|
|||||||
// Generate the relative path based on the path difference between `to` and
|
// Generate the relative path based on the path difference between `to` and
|
||||||
// `from`
|
// `from`
|
||||||
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
||||||
if (i === fromEnd || from.charCodeAt(i) === 92/*\*/) {
|
if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
|
||||||
if (out.length === 0)
|
if (out.length === 0)
|
||||||
out += '..';
|
out += '..';
|
||||||
else
|
else
|
||||||
@ -665,7 +680,7 @@ const win32 = {
|
|||||||
return out + toOrig.slice(toStart + lastCommonSep, toEnd);
|
return out + toOrig.slice(toStart + lastCommonSep, toEnd);
|
||||||
else {
|
else {
|
||||||
toStart += lastCommonSep;
|
toStart += lastCommonSep;
|
||||||
if (toOrig.charCodeAt(toStart) === 92/*\*/)
|
if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH)
|
||||||
++toStart;
|
++toStart;
|
||||||
return toOrig.slice(toStart, toEnd);
|
return toOrig.slice(toStart, toEnd);
|
||||||
}
|
}
|
||||||
@ -685,22 +700,22 @@ const win32 = {
|
|||||||
|
|
||||||
if (resolvedPath.length >= 3) {
|
if (resolvedPath.length >= 3) {
|
||||||
var code = resolvedPath.charCodeAt(0);
|
var code = resolvedPath.charCodeAt(0);
|
||||||
if (code === 92/*\*/) {
|
if (code === CHAR_BACKWARD_SLASH) {
|
||||||
// Possible UNC root
|
// Possible UNC root
|
||||||
|
|
||||||
if (resolvedPath.charCodeAt(1) === 92/*\*/) {
|
if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
|
||||||
code = resolvedPath.charCodeAt(2);
|
code = resolvedPath.charCodeAt(2);
|
||||||
if (code !== 63/*?*/ && code !== 46/*.*/) {
|
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
|
||||||
// Matched non-long UNC root, convert the path to a long UNC path
|
// Matched non-long UNC root, convert the path to a long UNC path
|
||||||
return '\\\\?\\UNC\\' + resolvedPath.slice(2);
|
return '\\\\?\\UNC\\' + resolvedPath.slice(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
|
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
|
||||||
(code >= 97/*a*/ && code <= 122/*z*/)) {
|
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
|
||||||
// Possible device root
|
// Possible device root
|
||||||
|
|
||||||
if (resolvedPath.charCodeAt(1) === 58/*:*/ &&
|
if (resolvedPath.charCodeAt(1) === CHAR_COLON &&
|
||||||
resolvedPath.charCodeAt(2) === 92/*\*/) {
|
resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
|
||||||
// Matched device root, convert the path to a long UNC path
|
// Matched device root, convert the path to a long UNC path
|
||||||
return '\\\\?\\' + resolvedPath;
|
return '\\\\?\\' + resolvedPath;
|
||||||
}
|
}
|
||||||
@ -723,20 +738,20 @@ const win32 = {
|
|||||||
|
|
||||||
// Try to match a root
|
// Try to match a root
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Possible UNC root
|
// Possible UNC root
|
||||||
|
|
||||||
rootEnd = offset = 1;
|
rootEnd = offset = 1;
|
||||||
|
|
||||||
code = path.charCodeAt(1);
|
code = path.charCodeAt(1);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Matched double path separator at beginning
|
// Matched double path separator at beginning
|
||||||
var j = 2;
|
var j = 2;
|
||||||
var last = j;
|
var last = j;
|
||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -745,7 +760,7 @@ const win32 = {
|
|||||||
// Match 1 or more path separators
|
// Match 1 or more path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code !== 47/*/*/ && code !== 92/*\*/)
|
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -754,7 +769,7 @@ const win32 = {
|
|||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j === len) {
|
if (j === len) {
|
||||||
@ -771,20 +786,20 @@ const win32 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
|
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
|
||||||
(code >= 97/*a*/ && code <= 122/*z*/)) {
|
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
|
||||||
// Possible device root
|
// Possible device root
|
||||||
|
|
||||||
if (path.charCodeAt(1) === 58/*:*/) {
|
if (path.charCodeAt(1) === CHAR_COLON) {
|
||||||
rootEnd = offset = 2;
|
rootEnd = offset = 2;
|
||||||
if (len > 2) {
|
if (len > 2) {
|
||||||
code = path.charCodeAt(2);
|
code = path.charCodeAt(2);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
rootEnd = offset = 3;
|
rootEnd = offset = 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// `path` contains just a path separator, exit early to avoid
|
// `path` contains just a path separator, exit early to avoid
|
||||||
// unnecessary work
|
// unnecessary work
|
||||||
return path;
|
return path;
|
||||||
@ -792,7 +807,7 @@ const win32 = {
|
|||||||
|
|
||||||
for (var i = len - 1; i >= offset; --i) {
|
for (var i = len - 1; i >= offset; --i) {
|
||||||
code = path.charCodeAt(i);
|
code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
end = i;
|
end = i;
|
||||||
break;
|
break;
|
||||||
@ -827,9 +842,9 @@ const win32 = {
|
|||||||
// disregarded
|
// disregarded
|
||||||
if (path.length >= 2) {
|
if (path.length >= 2) {
|
||||||
const drive = path.charCodeAt(0);
|
const drive = path.charCodeAt(0);
|
||||||
if ((drive >= 65/*A*/ && drive <= 90/*Z*/) ||
|
if ((drive >= CHAR_UPPERCASE_A && drive <= CHAR_UPPERCASE_Z) ||
|
||||||
(drive >= 97/*a*/ && drive <= 122/*z*/)) {
|
(drive >= CHAR_LOWERCASE_A && drive <= CHAR_LOWERCASE_Z)) {
|
||||||
if (path.charCodeAt(1) === 58/*:*/)
|
if (path.charCodeAt(1) === CHAR_COLON)
|
||||||
start = 2;
|
start = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -841,7 +856,7 @@ const win32 = {
|
|||||||
var firstNonSlashEnd = -1;
|
var firstNonSlashEnd = -1;
|
||||||
for (i = path.length - 1; i >= start; --i) {
|
for (i = path.length - 1; i >= start; --i) {
|
||||||
const code = path.charCodeAt(i);
|
const code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -881,7 +896,7 @@ const win32 = {
|
|||||||
} else {
|
} else {
|
||||||
for (i = path.length - 1; i >= start; --i) {
|
for (i = path.length - 1; i >= start; --i) {
|
||||||
const code = path.charCodeAt(i);
|
const code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -919,16 +934,16 @@ const win32 = {
|
|||||||
// disregarded
|
// disregarded
|
||||||
if (path.length >= 2) {
|
if (path.length >= 2) {
|
||||||
const code = path.charCodeAt(0);
|
const code = path.charCodeAt(0);
|
||||||
if (path.charCodeAt(1) === 58/*:*/ &&
|
if (path.charCodeAt(1) === CHAR_COLON &&
|
||||||
((code >= 65/*A*/ && code <= 90/*Z*/) ||
|
((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
|
||||||
(code >= 97/*a*/ && code <= 122/*z*/))) {
|
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z))) {
|
||||||
start = startPart = 2;
|
start = startPart = 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = path.length - 1; i >= start; --i) {
|
for (var i = path.length - 1; i >= start; --i) {
|
||||||
const code = path.charCodeAt(i);
|
const code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -943,7 +958,7 @@ const win32 = {
|
|||||||
matchedSlash = false;
|
matchedSlash = false;
|
||||||
end = i + 1;
|
end = i + 1;
|
||||||
}
|
}
|
||||||
if (code === 46/*.*/) {
|
if (code === CHAR_DOT) {
|
||||||
// If this is our first dot, mark it as the start of our extension
|
// If this is our first dot, mark it as the start of our extension
|
||||||
if (startDot === -1)
|
if (startDot === -1)
|
||||||
startDot = i;
|
startDot = i;
|
||||||
@ -992,19 +1007,19 @@ const win32 = {
|
|||||||
|
|
||||||
// Try to match a root
|
// Try to match a root
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Possible UNC root
|
// Possible UNC root
|
||||||
|
|
||||||
code = path.charCodeAt(1);
|
code = path.charCodeAt(1);
|
||||||
rootEnd = 1;
|
rootEnd = 1;
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// Matched double path separator at beginning
|
// Matched double path separator at beginning
|
||||||
var j = 2;
|
var j = 2;
|
||||||
var last = j;
|
var last = j;
|
||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -1013,7 +1028,7 @@ const win32 = {
|
|||||||
// Match 1 or more path separators
|
// Match 1 or more path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code !== 47/*/*/ && code !== 92/*\*/)
|
if (code !== CHAR_FORWARD_SLASH && code !== CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j < len && j !== last) {
|
if (j < len && j !== last) {
|
||||||
@ -1022,7 +1037,7 @@ const win32 = {
|
|||||||
// Match 1 or more non-path separators
|
// Match 1 or more non-path separators
|
||||||
for (; j < len; ++j) {
|
for (; j < len; ++j) {
|
||||||
code = path.charCodeAt(j);
|
code = path.charCodeAt(j);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/)
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (j === len) {
|
if (j === len) {
|
||||||
@ -1037,15 +1052,15 @@ const win32 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ((code >= 65/*A*/ && code <= 90/*Z*/) ||
|
} else if ((code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
|
||||||
(code >= 97/*a*/ && code <= 122/*z*/)) {
|
(code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z)) {
|
||||||
// Possible device root
|
// Possible device root
|
||||||
|
|
||||||
if (path.charCodeAt(1) === 58/*:*/) {
|
if (path.charCodeAt(1) === CHAR_COLON) {
|
||||||
rootEnd = 2;
|
rootEnd = 2;
|
||||||
if (len > 2) {
|
if (len > 2) {
|
||||||
code = path.charCodeAt(2);
|
code = path.charCodeAt(2);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
if (len === 3) {
|
if (len === 3) {
|
||||||
// `path` contains just a drive root, exit early to avoid
|
// `path` contains just a drive root, exit early to avoid
|
||||||
// unnecessary work
|
// unnecessary work
|
||||||
@ -1062,7 +1077,7 @@ const win32 = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (code === 47/*/*/ || code === 92/*\*/) {
|
} else if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// `path` contains just a path separator, exit early to avoid
|
// `path` contains just a path separator, exit early to avoid
|
||||||
// unnecessary work
|
// unnecessary work
|
||||||
ret.root = ret.dir = path;
|
ret.root = ret.dir = path;
|
||||||
@ -1085,7 +1100,7 @@ const win32 = {
|
|||||||
// Get non-dir info
|
// Get non-dir info
|
||||||
for (; i >= rootEnd; --i) {
|
for (; i >= rootEnd; --i) {
|
||||||
code = path.charCodeAt(i);
|
code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/ || code === 92/*\*/) {
|
if (code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -1100,7 +1115,7 @@ const win32 = {
|
|||||||
matchedSlash = false;
|
matchedSlash = false;
|
||||||
end = i + 1;
|
end = i + 1;
|
||||||
}
|
}
|
||||||
if (code === 46/*.*/) {
|
if (code === CHAR_DOT) {
|
||||||
// If this is our first dot, mark it as the start of our extension
|
// If this is our first dot, mark it as the start of our extension
|
||||||
if (startDot === -1)
|
if (startDot === -1)
|
||||||
startDot = i;
|
startDot = i;
|
||||||
@ -1174,7 +1189,7 @@ const posix = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
resolvedPath = path + '/' + resolvedPath;
|
resolvedPath = path + '/' + resolvedPath;
|
||||||
resolvedAbsolute = path.charCodeAt(0) === 47/*/*/;
|
resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point the path should be resolved to a full absolute path, but
|
// At this point the path should be resolved to a full absolute path, but
|
||||||
@ -1202,8 +1217,9 @@ const posix = {
|
|||||||
if (path.length === 0)
|
if (path.length === 0)
|
||||||
return '.';
|
return '.';
|
||||||
|
|
||||||
const isAbsolute = path.charCodeAt(0) === 47/*/*/;
|
const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
||||||
const trailingSeparator = path.charCodeAt(path.length - 1) === 47/*/*/;
|
const trailingSeparator =
|
||||||
|
path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
|
||||||
|
|
||||||
// Normalize the path
|
// Normalize the path
|
||||||
path = normalizeStringPosix(path, !isAbsolute);
|
path = normalizeStringPosix(path, !isAbsolute);
|
||||||
@ -1221,7 +1237,7 @@ const posix = {
|
|||||||
|
|
||||||
isAbsolute: function isAbsolute(path) {
|
isAbsolute: function isAbsolute(path) {
|
||||||
assertPath(path);
|
assertPath(path);
|
||||||
return path.length > 0 && path.charCodeAt(0) === 47/*/*/;
|
return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
@ -1261,7 +1277,7 @@ const posix = {
|
|||||||
// Trim any leading backslashes
|
// Trim any leading backslashes
|
||||||
var fromStart = 1;
|
var fromStart = 1;
|
||||||
for (; fromStart < from.length; ++fromStart) {
|
for (; fromStart < from.length; ++fromStart) {
|
||||||
if (from.charCodeAt(fromStart) !== 47/*/*/)
|
if (from.charCodeAt(fromStart) !== CHAR_FORWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var fromEnd = from.length;
|
var fromEnd = from.length;
|
||||||
@ -1270,7 +1286,7 @@ const posix = {
|
|||||||
// Trim any leading backslashes
|
// Trim any leading backslashes
|
||||||
var toStart = 1;
|
var toStart = 1;
|
||||||
for (; toStart < to.length; ++toStart) {
|
for (; toStart < to.length; ++toStart) {
|
||||||
if (to.charCodeAt(toStart) !== 47/*/*/)
|
if (to.charCodeAt(toStart) !== CHAR_FORWARD_SLASH)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
var toEnd = to.length;
|
var toEnd = to.length;
|
||||||
@ -1283,7 +1299,7 @@ const posix = {
|
|||||||
for (; i <= length; ++i) {
|
for (; i <= length; ++i) {
|
||||||
if (i === length) {
|
if (i === length) {
|
||||||
if (toLen > length) {
|
if (toLen > length) {
|
||||||
if (to.charCodeAt(toStart + i) === 47/*/*/) {
|
if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
|
||||||
// We get here if `from` is the exact base path for `to`.
|
// We get here if `from` is the exact base path for `to`.
|
||||||
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
// For example: from='/foo/bar'; to='/foo/bar/baz'
|
||||||
return to.slice(toStart + i + 1);
|
return to.slice(toStart + i + 1);
|
||||||
@ -1293,7 +1309,7 @@ const posix = {
|
|||||||
return to.slice(toStart + i);
|
return to.slice(toStart + i);
|
||||||
}
|
}
|
||||||
} else if (fromLen > length) {
|
} else if (fromLen > length) {
|
||||||
if (from.charCodeAt(fromStart + i) === 47/*/*/) {
|
if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
|
||||||
// We get here if `to` is the exact base path for `from`.
|
// We get here if `to` is the exact base path for `from`.
|
||||||
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
// For example: from='/foo/bar/baz'; to='/foo/bar'
|
||||||
lastCommonSep = i;
|
lastCommonSep = i;
|
||||||
@ -1309,7 +1325,7 @@ const posix = {
|
|||||||
var toCode = to.charCodeAt(toStart + i);
|
var toCode = to.charCodeAt(toStart + i);
|
||||||
if (fromCode !== toCode)
|
if (fromCode !== toCode)
|
||||||
break;
|
break;
|
||||||
else if (fromCode === 47/*/*/)
|
else if (fromCode === CHAR_FORWARD_SLASH)
|
||||||
lastCommonSep = i;
|
lastCommonSep = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1317,7 +1333,7 @@ const posix = {
|
|||||||
// Generate the relative path based on the path difference between `to`
|
// Generate the relative path based on the path difference between `to`
|
||||||
// and `from`
|
// and `from`
|
||||||
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
|
||||||
if (i === fromEnd || from.charCodeAt(i) === 47/*/*/) {
|
if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
||||||
if (out.length === 0)
|
if (out.length === 0)
|
||||||
out += '..';
|
out += '..';
|
||||||
else
|
else
|
||||||
@ -1331,7 +1347,7 @@ const posix = {
|
|||||||
return out + to.slice(toStart + lastCommonSep);
|
return out + to.slice(toStart + lastCommonSep);
|
||||||
else {
|
else {
|
||||||
toStart += lastCommonSep;
|
toStart += lastCommonSep;
|
||||||
if (to.charCodeAt(toStart) === 47/*/*/)
|
if (to.charCodeAt(toStart) === CHAR_FORWARD_SLASH)
|
||||||
++toStart;
|
++toStart;
|
||||||
return to.slice(toStart);
|
return to.slice(toStart);
|
||||||
}
|
}
|
||||||
@ -1348,12 +1364,12 @@ const posix = {
|
|||||||
if (path.length === 0)
|
if (path.length === 0)
|
||||||
return '.';
|
return '.';
|
||||||
var code = path.charCodeAt(0);
|
var code = path.charCodeAt(0);
|
||||||
var hasRoot = (code === 47/*/*/);
|
var hasRoot = (code === CHAR_FORWARD_SLASH);
|
||||||
var end = -1;
|
var end = -1;
|
||||||
var matchedSlash = true;
|
var matchedSlash = true;
|
||||||
for (var i = path.length - 1; i >= 1; --i) {
|
for (var i = path.length - 1; i >= 1; --i) {
|
||||||
code = path.charCodeAt(i);
|
code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/) {
|
if (code === CHAR_FORWARD_SLASH) {
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
end = i;
|
end = i;
|
||||||
break;
|
break;
|
||||||
@ -1389,7 +1405,7 @@ const posix = {
|
|||||||
var firstNonSlashEnd = -1;
|
var firstNonSlashEnd = -1;
|
||||||
for (i = path.length - 1; i >= 0; --i) {
|
for (i = path.length - 1; i >= 0; --i) {
|
||||||
const code = path.charCodeAt(i);
|
const code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/) {
|
if (code === CHAR_FORWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -1428,7 +1444,7 @@ const posix = {
|
|||||||
return path.slice(start, end);
|
return path.slice(start, end);
|
||||||
} else {
|
} else {
|
||||||
for (i = path.length - 1; i >= 0; --i) {
|
for (i = path.length - 1; i >= 0; --i) {
|
||||||
if (path.charCodeAt(i) === 47/*/*/) {
|
if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -1461,7 +1477,7 @@ const posix = {
|
|||||||
var preDotState = 0;
|
var preDotState = 0;
|
||||||
for (var i = path.length - 1; i >= 0; --i) {
|
for (var i = path.length - 1; i >= 0; --i) {
|
||||||
const code = path.charCodeAt(i);
|
const code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/) {
|
if (code === CHAR_FORWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -1476,7 +1492,7 @@ const posix = {
|
|||||||
matchedSlash = false;
|
matchedSlash = false;
|
||||||
end = i + 1;
|
end = i + 1;
|
||||||
}
|
}
|
||||||
if (code === 46/*.*/) {
|
if (code === CHAR_DOT) {
|
||||||
// If this is our first dot, mark it as the start of our extension
|
// If this is our first dot, mark it as the start of our extension
|
||||||
if (startDot === -1)
|
if (startDot === -1)
|
||||||
startDot = i;
|
startDot = i;
|
||||||
@ -1519,7 +1535,7 @@ const posix = {
|
|||||||
if (path.length === 0)
|
if (path.length === 0)
|
||||||
return ret;
|
return ret;
|
||||||
var code = path.charCodeAt(0);
|
var code = path.charCodeAt(0);
|
||||||
var isAbsolute = (code === 47/*/*/);
|
var isAbsolute = (code === CHAR_FORWARD_SLASH);
|
||||||
var start;
|
var start;
|
||||||
if (isAbsolute) {
|
if (isAbsolute) {
|
||||||
ret.root = '/';
|
ret.root = '/';
|
||||||
@ -1540,7 +1556,7 @@ const posix = {
|
|||||||
// Get non-dir info
|
// Get non-dir info
|
||||||
for (; i >= start; --i) {
|
for (; i >= start; --i) {
|
||||||
code = path.charCodeAt(i);
|
code = path.charCodeAt(i);
|
||||||
if (code === 47/*/*/) {
|
if (code === CHAR_FORWARD_SLASH) {
|
||||||
// If we reached a path separator that was not part of a set of path
|
// If we reached a path separator that was not part of a set of path
|
||||||
// separators at the end of the string, stop now
|
// separators at the end of the string, stop now
|
||||||
if (!matchedSlash) {
|
if (!matchedSlash) {
|
||||||
@ -1555,7 +1571,7 @@ const posix = {
|
|||||||
matchedSlash = false;
|
matchedSlash = false;
|
||||||
end = i + 1;
|
end = i + 1;
|
||||||
}
|
}
|
||||||
if (code === 46/*.*/) {
|
if (code === CHAR_DOT) {
|
||||||
// If this is our first dot, mark it as the start of our extension
|
// If this is our first dot, mark it as the start of our extension
|
||||||
if (startDot === -1)
|
if (startDot === -1)
|
||||||
startDot = i;
|
startDot = i;
|
||||||
|
1
node.gyp
1
node.gyp
@ -95,6 +95,7 @@
|
|||||||
'lib/internal/crypto/random.js',
|
'lib/internal/crypto/random.js',
|
||||||
'lib/internal/crypto/sig.js',
|
'lib/internal/crypto/sig.js',
|
||||||
'lib/internal/crypto/util.js',
|
'lib/internal/crypto/util.js',
|
||||||
|
'lib/internal/constants.js',
|
||||||
'lib/internal/encoding.js',
|
'lib/internal/encoding.js',
|
||||||
'lib/internal/errors.js',
|
'lib/internal/errors.js',
|
||||||
'lib/internal/freelist.js',
|
'lib/internal/freelist.js',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user