@@ -1540,7 +1540,11 @@ function pathToFileURL(filepath, options = kEmptyObject) {
1540
1540
if ( ( windows ?? isWindows ) && StringPrototypeStartsWith ( filepath , '\\\\' ) ) {
1541
1541
const outURL = new URL ( 'file://' ) ;
1542
1542
// UNC path format: \\server\share\resource
1543
- const hostnameEndIndex = StringPrototypeIndexOf ( filepath , '\\' , 2 ) ;
1543
+ // Handle extended UNC path and standard UNC path
1544
+ // \\?\UNC\ prefix should be ignored. (see https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=registry)
1545
+ const isExtendedUNC = StringPrototypeStartsWith ( filepath , '\\\\?\\UNC\\' ) ;
1546
+ const prefixLength = isExtendedUNC ? 8 : 2 ;
1547
+ const hostnameEndIndex = StringPrototypeIndexOf ( filepath , '\\' , prefixLength ) ;
1544
1548
if ( hostnameEndIndex === - 1 ) {
1545
1549
throw new ERR_INVALID_ARG_VALUE (
1546
1550
'path' ,
@@ -1555,7 +1559,7 @@ function pathToFileURL(filepath, options = kEmptyObject) {
1555
1559
'Empty UNC servername' ,
1556
1560
) ;
1557
1561
}
1558
- const hostname = StringPrototypeSlice ( filepath , 2 , hostnameEndIndex ) ;
1562
+ const hostname = StringPrototypeSlice ( filepath , prefixLength , hostnameEndIndex ) ;
1559
1563
outURL . hostname = domainToASCII ( hostname ) ;
1560
1564
outURL . pathname = encodePathChars (
1561
1565
RegExpPrototypeSymbolReplace ( backslashRegEx , StringPrototypeSlice ( filepath , hostnameEndIndex ) , '/' ) ,
0 commit comments