MCPcopy Index your code
hub / github.com/nodejs/node / getPathFromURLWin32

Function getPathFromURLWin32

lib/internal/url.js:1472–1508  ·  view source on GitHub ↗
(url)

Source from the content-addressed store, hash-verified

1470}
1471
1472function getPathFromURLWin32(url) {
1473 const hostname = url.hostname;
1474 let pathname = url.pathname;
1475 for (let n = 0; n < pathname.length; n++) {
1476 if (pathname[n] === '%') {
1477 const third = StringPrototypeCodePointAt(pathname, n + 2) | 0x20;
1478 if ((pathname[n + 1] === '2' && third === 102) || // 2f 2F /
1479 (pathname[n + 1] === '5' && third === 99)) { // 5c 5C \
1480 throw new ERR_INVALID_FILE_URL_PATH(
1481 'must not include encoded \\ or / characters', url,
1482 );
1483 }
1484 }
1485 }
1486 pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\');
1487 // Fast-path: if there is no percent-encoding, avoid decodeURIComponent.
1488 if (StringPrototypeIncludes(pathname, '%')) {
1489 pathname = decodeURIComponent(pathname);
1490 }
1491 if (hostname !== '') {
1492 // If hostname is set, then we have a UNC path
1493 // Pass the hostname through domainToUnicode just in case
1494 // it is an IDN using punycode encoding. We do not need to worry
1495 // about percent encoding because the URL parser will have
1496 // already taken care of that for us. Note that this only
1497 // causes IDNs with an appropriate `xn--` prefix to be decoded.
1498 return `\\\\${domainToUnicode(hostname)}${pathname}`;
1499 }
1500 // Otherwise, it's a local path that requires a drive letter
1501 const letter = StringPrototypeCodePointAt(pathname, 1) | 0x20;
1502 const sep = StringPrototypeCharAt(pathname, 2);
1503 if (letter < CHAR_LOWERCASE_A || letter > CHAR_LOWERCASE_Z || // a..z A..Z
1504 (sep !== ':')) {
1505 throw new ERR_INVALID_FILE_URL_PATH('must be absolute', url);
1506 }
1507 return StringPrototypeSlice(pathname, 1);
1508}
1509
1510function getPathBufferFromURLWin32(url) {
1511 const hostname = url.hostname;

Callers 1

fileURLToPathFunction · 0.85

Calls 2

domainToUnicodeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…