diff --git a/lib/path.js b/lib/path.js index 658b5d6901df..c42294b2beb1 100644 --- a/lib/path.js +++ b/lib/path.js @@ -1275,6 +1275,21 @@ const posix = { // At this point the path should be resolved to a full absolute path, but // handle relative paths to be safe (might happen when process.cwd() fails) + // Already-normalized absolute paths skip normalizeString. cwd-failed + // relative results stay on that path so '' still resolves to '.'. + if (resolvedAbsolute && + StringPrototypeIndexOf(resolvedPath, '.') === -1 && + StringPrototypeIndexOf(resolvedPath, '//') === -1) { + // The concat above always appends one '/'. + if (resolvedPath.length > 1 && + StringPrototypeCharCodeAt(resolvedPath, resolvedPath.length - 1) === + CHAR_FORWARD_SLASH) { + resolvedPath = StringPrototypeSlice(resolvedPath, 0, -1); + } + return StringPrototypeCharCodeAt(resolvedPath, 0) === + CHAR_FORWARD_SLASH ? resolvedPath : `/${resolvedPath}`; + } + // Normalize the path resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/', isPosixPathSeparator);