Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 16 additions & 5 deletions lib/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -402,11 +402,22 @@ const win32 = {
device = `\\\\${firstPart}`;
rootEnd = 4;
const colonIndex = StringPrototypeIndexOf(path, ':');
// Special case: handle \\?\COM1: or similar reserved device paths
const possibleDevice = StringPrototypeSlice(path, 4, colonIndex + 1);
if (isWindowsReservedName(possibleDevice, possibleDevice.length - 1)) {
device = `\\\\?\\${possibleDevice}`;
rootEnd = 4 + possibleDevice.length;

if (colonIndex !== -1) {
// Handle \\?\COM1: or similar reserved device paths with colon
const possibleDevice = StringPrototypeSlice(path, 4, colonIndex + 1);
if (isWindowsReservedName(possibleDevice, possibleDevice.length - 1)) {
device = `\\\\?\\${possibleDevice}`;
rootEnd = 4 + possibleDevice.length;
}
} else {
// Handle \\.\CON or \\?\CON where the colon is missing
const possibleDevice = StringPrototypeSlice(path, 4);
const upper = StringPrototypeToUpperCase(possibleDevice);
if (ArrayPrototypeIncludes(WINDOWS_RESERVED_NAMES, upper)) {
device = `\\\\.\\${possibleDevice}`;
rootEnd = 4 + possibleDevice.length;
}
}
} else if (j === len) {
// We matched a UNC root only
Expand Down
27 changes: 27 additions & 0 deletions test/parallel/test-path-win32-normalize-device-missing-colon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const path = require('path');

// هذا السطر يمنع تشغيل الاختبار على غير ويندوز لأنه خاص بويندوز فقط
if (!common.isWindows)
common.skip('this test is for win32 only');

// Test cases for reserved device names missing the trailing colon
// See: https://github.com/nodejs/node/pull/[YOUR_PR_NUMBER] (optional)

// 1. Check \\.\CON (Missing colon)
assert.strictEqual(path.win32.normalize('\\\\.\\CON'), '\\\\.\\CON');
assert.strictEqual(path.win32.normalize('\\\\.\\con'), '\\\\.\\con'); // Case insensitive

// 2. Check \\?\CON (Missing colon)
assert.strictEqual(path.win32.normalize('\\\\?\\CON'), '\\\\?\\CON');
assert.strictEqual(path.win32.normalize('\\\\?\\con'), '\\\\?\\con');

// 3. Check that regular files are NOT affected (Sanity check)
assert.strictEqual(path.win32.normalize('\\\\.\\PhysicalDrive0'), '\\\\.\\PhysicalDrive0');

// 4. Check join behavior (to ensure it acts as a root)
// If it's a root, joining '..' should not strip the device.
const joined = path.win32.join('\\\\.\\CON', '..');
assert.strictEqual(joined, '\\\\.\\CON');