@@ -397,18 +397,29 @@ const win32 = {
397397 j ++ ;
398398 }
399399 if ( j === len || j !== last ) {
400- if ( firstPart === '.' || firstPart === '?' ) {
401- // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
402- device = `\\\\${ firstPart } ` ;
403- rootEnd = 4 ;
404- const colonIndex = StringPrototypeIndexOf ( path , ':' ) ;
405- // Special case: handle \\?\COM1: or similar reserved device paths
400+ if ( firstPart === '.' || firstPart === '?' ) {
401+ // We matched a device root (e.g. \\\\.\\PHYSICALDRIVE0)
402+ device = `\\\\${ firstPart } ` ;
403+ rootEnd = 4 ;
404+ const colonIndex = StringPrototypeIndexOf ( path , ':' ) ;
405+
406+ if ( colonIndex !== - 1 ) {
407+ // Handle \\?\COM1: or similar reserved device paths with colon
406408 const possibleDevice = StringPrototypeSlice ( path , 4 , colonIndex + 1 ) ;
407409 if ( isWindowsReservedName ( possibleDevice , possibleDevice . length - 1 ) ) {
408410 device = `\\\\?\\${ possibleDevice } ` ;
409411 rootEnd = 4 + possibleDevice . length ;
410412 }
411- } else if ( j === len ) {
413+ } else {
414+ // Handle \\.\CON or \\?\CON where the colon is missing
415+ const possibleDevice = StringPrototypeSlice ( path , 4 ) ;
416+ const upper = StringPrototypeToUpperCase ( possibleDevice ) ;
417+ if ( ArrayPrototypeIncludes ( WINDOWS_RESERVED_NAMES , upper ) ) {
418+ device = `\\\\.\\${ possibleDevice } ` ;
419+ rootEnd = 4 + possibleDevice . length ;
420+ }
421+ }
422+ } else if ( j === len ) {
412423 // We matched a UNC root only
413424 // Return the normalized version of the UNC root since there
414425 // is nothing left to process
0 commit comments