| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c2837f0 commit 2a5ac93
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1512,32 +1512,35 @@ function fileURLToPath(path, options = kEmptyObject) { | |||
| 1512 | 1512 | ||
| 1513 | 1513 | function pathToFileURL(filepath, options = kEmptyObject) { | |
| 1514 | 1514 | const windows = options?.windows ?? isWindows; | |
| 1515 | - if (windows && StringPrototypeStartsWith(filepath, '\\\\')) { | ||
| 1515 | + const isUNC = windows && StringPrototypeStartsWith(filepath, '\\\\'); | ||
| 1516 | + let resolved = isUNC ? | ||
| 1517 | + filepath : | ||
| 1518 | + (windows ? path.win32.resolve(filepath) : path.posix.resolve(filepath)); | ||
| 1519 | + if (isUNC || (windows && StringPrototypeStartsWith(resolved, '\\\\'))) { | ||
| 1516 | 1520 | // UNC path format: \\server\share\resource | |
| 1517 | 1521 | // Handle extended UNC path and standard UNC path | |
| 1518 | 1522 | // "\\?\UNC\" path prefix should be ignored. | |
| 1519 | 1523 | // Ref: https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation | |
| 1520 | - const isExtendedUNC = StringPrototypeStartsWith(filepath, '\\\\?\\UNC\\'); | ||
| 1524 | + const isExtendedUNC = StringPrototypeStartsWith(resolved, '\\\\?\\UNC\\'); | ||
| 1521 | 1525 | const prefixLength = isExtendedUNC ? 8 : 2; | |
| 1522 | - const hostnameEndIndex = StringPrototypeIndexOf(filepath, '\\', prefixLength); | ||
| 1526 | + const hostnameEndIndex = StringPrototypeIndexOf(resolved, '\\', prefixLength); | ||
| 1523 | 1527 | if (hostnameEndIndex === -1) { | |
| 1524 | 1528 | throw new ERR_INVALID_ARG_VALUE( | |
| 1525 | 1529 | 'path', | |
| 1526 | - filepath, | ||
| 1530 | + resolved, | ||
| 1527 | 1531 | 'Missing UNC resource path', | |
| 1528 | 1532 | ); | |
| 1529 | 1533 | } | |
| 1530 | 1534 | if (hostnameEndIndex === 2) { | |
| 1531 | 1535 | throw new ERR_INVALID_ARG_VALUE( | |
| 1532 | 1536 | 'path', | |
| 1533 | - filepath, | ||
| 1537 | + resolved, | ||
| 1534 | 1538 | 'Empty UNC servername', | |
| 1535 | 1539 | ); | |
| 1536 | 1540 | } | |
| 1537 | - const hostname = StringPrototypeSlice(filepath, prefixLength, hostnameEndIndex); | ||
| 1538 | - return new URL(StringPrototypeSlice(filepath, hostnameEndIndex), hostname, kCreateURLFromWindowsPathSymbol); | ||
| 1541 | + const hostname = StringPrototypeSlice(resolved, prefixLength, hostnameEndIndex); | ||
| 1542 | + return new URL(StringPrototypeSlice(resolved, hostnameEndIndex), hostname, kCreateURLFromWindowsPathSymbol); | ||
| 1539 | 1543 | } | |
| 1540 | - let resolved = windows ? path.win32.resolve(filepath) : path.posix.resolve(filepath); | ||
| 1541 | 1544 | // path.resolve strips trailing slashes so we must add them back | |
| 1542 | 1545 | const filePathLast = StringPrototypeCharCodeAt(filepath, | |
| 1543 | 1546 | filepath.length - 1); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments