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
fixup! fixup! fixup! lib: handle windows reserved device names on UNC
  • Loading branch information
RafaelGSS committed Aug 7, 2025
commit a2ad2953a44d427b8f1bff11a04e70106a86a98c
26 changes: 22 additions & 4 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,15 +564,33 @@ const win32 = {
}

// Skip normalization when reserved device names are present
const splitRegexp = /\\+/;
const parts = StringPrototypeSplit(joined, splitRegexp);
const parts = [];
let part = '';

for (let i = 0; i < joined.length; i++) {
if (joined[i] === '\\') {
if (part) parts.push(part);
part = '';
// Skip consecutive backslashes
while (i + 1 < joined.length && joined[i + 1] === '\\') i++;
} else {
part += joined[i];
}
}
// Add the final part if any
if (part) parts.push(part);

const replaceRegexp = /\//g;
// Check if any part has a Windows reserved name
if (parts.some((p) => {
const colonIndex = StringPrototypeIndexOf(p, ':');
return colonIndex !== -1 && isWindowsReservedName(p, colonIndex);
})) {
return StringPrototypeReplace(joined, replaceRegexp, '\\');
// Replace forward slashes with backslashes
let result = '';
for (let i = 0; i < joined.length; i++) {
result += joined[i] === '/' ? '\\' : joined[i];
}
return result;
}

return win32.normalize(joined);
Expand Down
Loading