Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fixup! fixup! lib: handle windows reserved device names on UNC
  • Loading branch information
RafaelGSS committed Jul 31, 2025
commit 3bfea8f86f75a55d55a53ddf48bd47dc2755ab20
12 changes: 8 additions & 4 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,9 @@ const win32 = {
// We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
device = `\\\\${firstPart}`;
rootEnd = 4;
const colonIndex = StringPrototypeIndexOf(path, ':');
// Special case: handle \\?\COM1: or similar reserved device paths
const possibleDevice = StringPrototypeSlice(path, 4, path.indexOf(':') + 1);
const possibleDevice = StringPrototypeSlice(path, 4, colonIndex + 1);
if (isWindowsReservedName(possibleDevice, possibleDevice.length - 1)) {
device = `\\\\?\\${possibleDevice}`;
rootEnd = 4 + possibleDevice.length;
Expand Down Expand Up @@ -563,12 +564,15 @@ const win32 = {
}

// Skip normalization when reserved device names are present
const parts = joined.split(/\\+/);
const splitRegexp = /\\+/;
const parts = StringPrototypeSplit(joined, splitRegexp);

const replaceRegexp = /\//g;
if (parts.some((p) => {
const colonIndex = p.indexOf(':');
const colonIndex = StringPrototypeIndexOf(p, ':');
return colonIndex !== -1 && isWindowsReservedName(p, colonIndex);
})) {
return joined.replace(/\//g, '\\');
return StringPrototypeReplace(joined, replaceRegexp, '\\');
}

return win32.normalize(joined);
Expand Down
Loading