* Make it easy to create small utilities that tweak a URL's path.
(cb)
| 2539 | * Make it easy to create small utilities that tweak a URL's path. |
| 2540 | */ |
| 2541 | function createSafeHandler(cb) { |
| 2542 | return input => { |
| 2543 | const type = getURLType(input); |
| 2544 | const base = buildSafeBase(input); |
| 2545 | const url = new URL(input, base); |
| 2546 | |
| 2547 | cb(url); |
| 2548 | |
| 2549 | const result = url.toString(); |
| 2550 | |
| 2551 | if (type === "absolute") { |
| 2552 | return result; |
| 2553 | } else if (type === "scheme-relative") { |
| 2554 | return result.slice(PROTOCOL.length); |
| 2555 | } else if (type === "path-absolute") { |
| 2556 | return result.slice(PROTOCOL_AND_HOST.length); |
| 2557 | } |
| 2558 | |
| 2559 | // This assumes that the callback will only change |
| 2560 | // the path, search and hash values. |
| 2561 | return computeRelativeURL(base, result); |
| 2562 | }; |
| 2563 | } |
| 2564 | |
| 2565 | function withBase(url, base) { |
| 2566 | return new URL(url, base).toString(); |
no test coverage detected
searching dependent graphs…