Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Comment on lines +96 to +97
Copy link
Member

@ChALkeR ChALkeR Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail on the following case:

> path.normalize('a\\d')
'a\\d'
> path.posix.normalize('a\\d')
'a\\d'

This code misses that isPathSeparator is an argument and could be isPosixPathSeparator.

}
let res = '';
let lastSegmentLength = 0;
let lastSlash = -1;
Expand Down