diff --git a/lib/path.js b/lib/path.js index 63b037cddfb986..ef385789cc8c9e 100644 --- a/lib/path.js +++ b/lib/path.js @@ -90,6 +90,12 @@ function isWindowsDeviceRoot(code) { // Resolves . and .. elements in a path with directory names function normalizeString(path, allowAboveRoot, separator, isPathSeparator) { + if (!path.includes(`${CHAR_DOT}${CHAR_FORWARD_SLASH}` && + !path.includes(`${CHAR_DOT}${CHAR_BACKWARD_SLASH}`) { + // Happy path: no . and .. elements - avoid string concatenation in cycle + const otherSeparator = separator === CHAR_FORWARD_SLASH ? CHAR_BACKWARD_SLASH : CHAR_FORWARD_SLASH; + return path.replaceAll(otherSeparator, separator); + } let res = ''; let lastSegmentLength = 0; let lastSlash = -1;