diff --git a/lib/path.js b/lib/path.js index 4bb385586166c4..c8d92f14af04de 100644 --- a/lib/path.js +++ b/lib/path.js @@ -21,10 +21,7 @@ 'use strict'; -const { - ERR_ASSERTION, - ERR_INVALID_ARG_TYPE -} = require('internal/errors').codes; +const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes; const { CHAR_UPPERCASE_A, CHAR_LOWERCASE_A, @@ -80,23 +77,16 @@ function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { res.charCodeAt(res.length - 2) !== CHAR_DOT) { if (res.length > 2) { const lastSlashIndex = res.lastIndexOf(separator); - if (lastSlashIndex !== res.length - 1) { - if (lastSlashIndex === -1) { - res = ''; - lastSegmentLength = 0; - } else { - res = res.slice(0, lastSlashIndex); - lastSegmentLength = res.length - 1 - res.lastIndexOf(separator); - } - lastSlash = i; - dots = 0; - continue; + if (lastSlashIndex === -1) { + res = ''; + lastSegmentLength = 0; } else { - throw new ERR_ASSERTION( - 'invariant violation: unreachable: ' + - JSON.stringify({ path, allowAboveRoot, separator }) - ); + res = res.slice(0, lastSlashIndex); + lastSegmentLength = res.length - 1 - res.lastIndexOf(separator); } + lastSlash = i; + dots = 0; + continue; } else if (res.length === 2 || res.length === 1) { res = ''; lastSegmentLength = 0;