* Joins two paths/URLs. * * All returned URLs will be normalized. * * @param aRoot The root path or URL. Assumed to reference a directory. * @param aPath The path or URL to be joined with the root. * @return A joined and normalized URL value.
(aRoot, aPath)
| 323 | * @return A joined and normalized URL value. |
| 324 | */ |
| 325 | function join(aRoot, aPath) { |
| 326 | const pathType = getURLType(aPath); |
| 327 | const rootType = getURLType(aRoot); |
| 328 | |
| 329 | aRoot = ensureDirectory(aRoot); |
| 330 | |
| 331 | if (pathType === "absolute") { |
| 332 | return withBase(aPath, undefined); |
| 333 | } |
| 334 | if (rootType === "absolute") { |
| 335 | return withBase(aPath, aRoot); |
| 336 | } |
| 337 | |
| 338 | if (pathType === "scheme-relative") { |
| 339 | return normalize(aPath); |
| 340 | } |
| 341 | if (rootType === "scheme-relative") { |
| 342 | return withBase(aPath, withBase(aRoot, PROTOCOL_AND_HOST)).slice( |
| 343 | PROTOCOL.length |
| 344 | ); |
| 345 | } |
| 346 | |
| 347 | if (pathType === "path-absolute") { |
| 348 | return normalize(aPath); |
| 349 | } |
| 350 | if (rootType === "path-absolute") { |
| 351 | return withBase(aPath, withBase(aRoot, PROTOCOL_AND_HOST)).slice( |
| 352 | PROTOCOL_AND_HOST.length |
| 353 | ); |
| 354 | } |
| 355 | |
| 356 | const base = buildSafeBase(aPath + aRoot); |
| 357 | const newPath = withBase(aPath, withBase(aRoot, base)); |
| 358 | return computeRelativeURL(base, newPath); |
| 359 | } |
| 360 | exports.join = join; |
| 361 | |
| 362 | /** |
no test coverage detected
searching dependent graphs…