@@ -1530,7 +1530,12 @@ function pathToFileURL(filepath, options = kEmptyObject) {
15301530if ( ( windows ?? isWindows ) && StringPrototypeStartsWith ( filepath , '\\\\' ) ) {
15311531const outURL = new URL ( 'file://' ) ;
15321532// UNC path format: \\server\share\resource
1533- const hostnameEndIndex = StringPrototypeIndexOf ( filepath , '\\' , 2 ) ;
1533+ // Handle extended UNC path and standard UNC path
1534+ // "\\?\UNC\" path prefix should be ignored.
1535+ // Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation
1536+ const isExtendedUNC = StringPrototypeStartsWith ( filepath , '\\\\?\\UNC\\' ) ;
1537+ const prefixLength = isExtendedUNC ? 8 : 2 ;
1538+ const hostnameEndIndex = StringPrototypeIndexOf ( filepath , '\\' , prefixLength ) ;
15341539if ( hostnameEndIndex === - 1 ) {
15351540throw new ERR_INVALID_ARG_VALUE (
15361541'path' ,
@@ -1545,7 +1550,7 @@ function pathToFileURL(filepath, options = kEmptyObject) {
15451550'Empty UNC servername' ,
15461551) ;
15471552}
1548- const hostname = StringPrototypeSlice ( filepath , 2 , hostnameEndIndex ) ;
1553+ const hostname = StringPrototypeSlice ( filepath , prefixLength , hostnameEndIndex ) ;
15491554outURL . hostname = domainToASCII ( hostname ) ;
15501555outURL . pathname = encodePathChars (
15511556RegExpPrototypeSymbolReplace ( backslashRegEx , StringPrototypeSlice ( filepath , hostnameEndIndex ) , '/' ) ,
0 commit comments