* 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)
| 2687 | * @return A joined and normalized URL value. |
| 2688 | */ |
| 2689 | function join(aRoot, aPath) { |
| 2690 | const pathType = getURLType(aPath); |
| 2691 | const rootType = getURLType(aRoot); |
| 2692 | |
| 2693 | aRoot = ensureDirectory(aRoot); |
| 2694 | |
| 2695 | if (pathType === "absolute") { |
| 2696 | return withBase(aPath, undefined); |
| 2697 | } |
| 2698 | if (rootType === "absolute") { |
| 2699 | return withBase(aPath, aRoot); |
| 2700 | } |
| 2701 | |
| 2702 | if (pathType === "scheme-relative") { |
| 2703 | return normalize(aPath); |
| 2704 | } |
| 2705 | if (rootType === "scheme-relative") { |
| 2706 | return withBase(aPath, withBase(aRoot, PROTOCOL_AND_HOST)).slice(PROTOCOL.length); |
| 2707 | } |
| 2708 | |
| 2709 | if (pathType === "path-absolute") { |
| 2710 | return normalize(aPath); |
| 2711 | } |
| 2712 | if (rootType === "path-absolute") { |
| 2713 | return withBase(aPath, withBase(aRoot, PROTOCOL_AND_HOST)).slice(PROTOCOL_AND_HOST.length); |
| 2714 | } |
| 2715 | |
| 2716 | const base = buildSafeBase(aPath + aRoot); |
| 2717 | const newPath = withBase(aPath, withBase(aRoot, base)); |
| 2718 | return computeRelativeURL(base, newPath); |
| 2719 | } |
| 2720 | exports.join = join; |
| 2721 | |
| 2722 | /** |
no test coverage detected
searching dependent graphs…