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