@@ -180,6 +180,29 @@ function glob(path, pattern, windows) {
180180 } ) ;
181181}
182182
183+ // Regular expressions to identify special device names in Windows.
184+ // COM to AUX (e.g., COM1, LPT1, NUL, CON, CONIN$, PRN, AUX) are reserved OS device names.
185+ // therefore, Paths like C:\path\to\COM1 map to \\.\COM1, referencing hardware or system streams.
186+ // Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file#maximum-path-length-limitation
187+
188+ // PhysicalDrive to Changer (e.g., PhysicalDrive1, TAPE0, Changer0) are not reserved OS device names.
189+ // Ref: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
190+ const windowDevicePatterns = [
191+ / ( [ \\ / ] ) ? ( C O M \d + ) $ / i,
192+ / ( [ \\ / ] ) ? ( L P T \d + ) $ / i,
193+ / ( [ \\ / ] ) ? ( N U L ) $ / i,
194+ / ( [ \\ / ] ) ? ( C O N ) $ / i,
195+ / ( [ \\ / ] ) ? ( P R N ) $ / i,
196+ / ( [ \\ / ] ) ? ( A U X ) $ / i,
197+ / ( [ \\ / ] ) ? ( C O N I N \$ ) $ / i,
198+ / ( [ \\ / ] ) ? ( C O N O U T \$ ) $ / i,
199+ / ^ ( P H Y S I C A L D R I V E \d + ) $ / i,
200+ / ^ ( P I P E \\ .+ ) $ / i,
201+ / ^ ( M A I L S L O T \\ .+ ) $ / i,
202+ / ^ ( T A P E \d + ) $ / i,
203+ / ^ ( C H A N G E R \d + ) $ / i,
204+ ] ;
205+
183206const win32 = {
184207 /**
185208 * path.resolve([from ...], to)
@@ -687,6 +710,19 @@ const win32 = {
687710 if ( typeof path !== 'string' || path . length === 0 )
688711 return path ;
689712
713+ // Check if the path matches any device pattern
714+ if ( windowDevicePatterns . some ( ( pattern ) => pattern . test ( path ) ) ) {
715+ let deviceName ;
716+ if ( / ^ ( P I P E \\ .+ ) $ / i. test ( path ) || / ^ ( M A I L S L O T \\ .+ ) $ / i. test ( path ) ) {
717+ // If the path starts with PIPE\ or MAILSLOT\, keep it as is
718+ deviceName = path ;
719+ } else {
720+ // Extract the last component after the last slash or backslash
721+ deviceName = path . split ( / [ \\ / ] / ) . pop ( ) ;
722+ }
723+ return `\\\\.\\${ deviceName } ` ;
724+ }
725+
690726 const resolvedPath = win32 . resolve ( path ) ;
691727
692728 if ( resolvedPath . length <= 2 )
0 commit comments