Skip to content

Commit a2ad295

Browse files
committed
fixup! fixup! fixup! lib: handle windows reserved device names on UNC
1 parent 3bfea8f commit a2ad295

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

lib/path.js

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -564,15 +564,33 @@ const win32 = {
564564
}
565565

566566
// Skip normalization when reserved device names are present
567-
const splitRegexp = /\\+/;
568-
const parts = StringPrototypeSplit(joined, splitRegexp);
567+
const parts = [];
568+
let part = '';
569+
570+
for (let i = 0; i < joined.length; i++) {
571+
if (joined[i] === '\\') {
572+
if (part) parts.push(part);
573+
part = '';
574+
// Skip consecutive backslashes
575+
while (i + 1 < joined.length && joined[i + 1] === '\\') i++;
576+
} else {
577+
part += joined[i];
578+
}
579+
}
580+
// Add the final part if any
581+
if (part) parts.push(part);
569582

570-
const replaceRegexp = /\//g;
583+
// Check if any part has a Windows reserved name
571584
if (parts.some((p) => {
572585
const colonIndex = StringPrototypeIndexOf(p, ':');
573586
return colonIndex !== -1 && isWindowsReservedName(p, colonIndex);
574587
})) {
575-
return StringPrototypeReplace(joined, replaceRegexp, '\\');
588+
// Replace forward slashes with backslashes
589+
let result = '';
590+
for (let i = 0; i < joined.length; i++) {
591+
result += joined[i] === '/' ? '\\' : joined[i];
592+
}
593+
return result;
576594
}
577595

578596
return win32.normalize(joined);

0 commit comments

Comments
 (0)