* Make it easy to create small utilities that tweak a URL's path.
(cb)
| 175 | * Make it easy to create small utilities that tweak a URL's path. |
| 176 | */ |
| 177 | function createSafeHandler(cb) { |
| 178 | return input => { |
| 179 | const type = getURLType(input); |
| 180 | const base = buildSafeBase(input); |
| 181 | const url = new URL(input, base); |
| 182 | |
| 183 | cb(url); |
| 184 | |
| 185 | const result = url.toString(); |
| 186 | |
| 187 | if (type === "absolute") { |
| 188 | return result; |
| 189 | } else if (type === "scheme-relative") { |
| 190 | return result.slice(PROTOCOL.length); |
| 191 | } else if (type === "path-absolute") { |
| 192 | return result.slice(PROTOCOL_AND_HOST.length); |
| 193 | } |
| 194 | |
| 195 | // This assumes that the callback will only change |
| 196 | // the path, search and hash values. |
| 197 | return computeRelativeURL(base, result); |
| 198 | }; |
| 199 | } |
| 200 | |
| 201 | function withBase(url, base) { |
| 202 | return new URL(url, base).toString(); |
no test coverage detected
searching dependent graphs…