diff --git a/lib/path.js b/lib/path.js index e376afae7c2daa..2301a6ebb8321f 100644 --- a/lib/path.js +++ b/lib/path.js @@ -50,11 +50,11 @@ function isWindowsDeviceRoot(code) { // Resolves . and .. elements in a path with directory names function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { - var res = ''; - var lastSegmentLength = 0; - var lastSlash = -1; - var dots = 0; - var code; + let res = ''; + let lastSegmentLength = 0; + let lastSlash = -1; + let dots = 0; + let code = 0; for (var i = 0; i <= path.length; ++i) { if (i < path.length) code = path.charCodeAt(i); @@ -66,7 +66,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { if (isPathSeparator(code)) { if (lastSlash === i - 1 || dots === 1) { // NOOP - } else if (lastSlash !== i - 1 && dots === 2) { + } else if (dots === 2) { if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== CHAR_DOT || res.charCodeAt(res.length - 2) !== CHAR_DOT) { @@ -82,7 +82,7 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { lastSlash = i; dots = 0; continue; - } else if (res.length === 2 || res.length === 1) { + } else if (res.length !== 0) { res = ''; lastSegmentLength = 0; lastSlash = i;