Skip to content

Commit 3bfea8f

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

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

lib/path.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,9 @@ const win32 = {
398398
// We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
399399
device = `\\\\${firstPart}`;
400400
rootEnd = 4;
401+
const colonIndex = StringPrototypeIndexOf(path, ':');
401402
// Special case: handle \\?\COM1: or similar reserved device paths
402-
const possibleDevice = StringPrototypeSlice(path, 4, path.indexOf(':') + 1);
403+
const possibleDevice = StringPrototypeSlice(path, 4, colonIndex + 1);
403404
if (isWindowsReservedName(possibleDevice, possibleDevice.length - 1)) {
404405
device = `\\\\?\\${possibleDevice}`;
405406
rootEnd = 4 + possibleDevice.length;
@@ -563,12 +564,15 @@ const win32 = {
563564
}
564565

565566
// Skip normalization when reserved device names are present
566-
const parts = joined.split(/\\+/);
567+
const splitRegexp = /\\+/;
568+
const parts = StringPrototypeSplit(joined, splitRegexp);
569+
570+
const replaceRegexp = /\//g;
567571
if (parts.some((p) => {
568-
const colonIndex = p.indexOf(':');
572+
const colonIndex = StringPrototypeIndexOf(p, ':');
569573
return colonIndex !== -1 && isWindowsReservedName(p, colonIndex);
570574
})) {
571-
return joined.replace(/\//g, '\\');
575+
return StringPrototypeReplace(joined, replaceRegexp, '\\');
572576
}
573577

574578
return win32.normalize(joined);

0 commit comments

Comments
 (0)