@@ -1540,7 +1540,12 @@ function pathToFileURL(filepath, options = kEmptyObject) {
15401540 if ( ( windows ?? isWindows ) && StringPrototypeStartsWith ( filepath , '\\\\' ) ) {
15411541 const outURL = new URL ( 'file://' ) ;
15421542 // UNC path format: \\server\share\resource
1543- const hostnameEndIndex = StringPrototypeIndexOf ( filepath , '\\' , 2 ) ;
1543+ // Handle extended UNC path and standard UNC path
1544+ // "\\?\UNC\" path prefix should be ignored.
1545+ // Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
1546+ const isExtendedUNC = StringPrototypeStartsWith ( filepath , '\\\\?\\UNC\\' ) ;
1547+ const prefixLength = isExtendedUNC ? 8 : 2 ;
1548+ const hostnameEndIndex = StringPrototypeIndexOf ( filepath , '\\' , prefixLength ) ;
15441549 if ( hostnameEndIndex === - 1 ) {
15451550 throw new ERR_INVALID_ARG_VALUE (
15461551 'path' ,
@@ -1555,7 +1560,7 @@ function pathToFileURL(filepath, options = kEmptyObject) {
15551560 'Empty UNC servername' ,
15561561 ) ;
15571562 }
1558- const hostname = StringPrototypeSlice ( filepath , 2 , hostnameEndIndex ) ;
1563+ const hostname = StringPrototypeSlice ( filepath , prefixLength , hostnameEndIndex ) ;
15591564 outURL . hostname = domainToASCII ( hostname ) ;
15601565 outURL . pathname = encodePathChars (
15611566 RegExpPrototypeSymbolReplace ( backslashRegEx , StringPrototypeSlice ( filepath , hostnameEndIndex ) , '/' ) ,
0 commit comments