(relativeUrlString, baseUrl)
| 571 | * @private @visibleForTesting |
| 572 | */ |
| 573 | export function resolveRelativeUrlFallback_(relativeUrlString, baseUrl) { |
| 574 | baseUrl = urlAsLocation(baseUrl); |
| 575 | relativeUrlString = relativeUrlString.replace(/\\/g, '/'); |
| 576 | const relativeUrl = parseUrlDeprecated(relativeUrlString); |
| 577 | |
| 578 | // Absolute URL. |
| 579 | if (relativeUrlString.toLowerCase().startsWith(relativeUrl.protocol)) { |
| 580 | return relativeUrl.href; |
| 581 | } |
| 582 | |
| 583 | // Protocol-relative URL. |
| 584 | if (relativeUrlString.startsWith('//')) { |
| 585 | return baseUrl.protocol + relativeUrlString; |
| 586 | } |
| 587 | |
| 588 | // Absolute path. |
| 589 | if (relativeUrlString.startsWith('/')) { |
| 590 | return baseUrl.origin + relativeUrlString; |
| 591 | } |
| 592 | |
| 593 | // Relative path. |
| 594 | return ( |
| 595 | baseUrl.origin + |
| 596 | baseUrl.pathname.replace(/\/[^/]*$/, '/') + |
| 597 | relativeUrlString |
| 598 | ); |
| 599 | } |
| 600 | |
| 601 | /** |
| 602 | * Add "__amp_source_origin" query parameter to the URL. |
no test coverage detected