@@ -12,6 +12,26 @@ export class UrlResolver {
1212 }
1313 }
1414
15+ /**
16+ * Resolves the `url` given the `baseUrl`.
17+ *
18+ * ## When the `baseUrl` is null
19+ *
20+ * `url` is resolved in the context of the current document.
21+ * If the document location is 'http://www.foo.com/base' and the `url` is 'path/to/here', the resolved url will be
22+ * 'http://www.foo.com/base/path/to/here'
23+ *
24+ * ## When the `baseUrl` is not null
25+ *
26+ * - when the `url` is null, the `baseUrl` is returned,
27+ * - due to a limitation in the process used to resolve urls (a HTMLLinkElement), `url` must not start with a `/`,
28+ * - if `url` is relative ('path/to/here', './path/to/here'), the resolved url is a combination of `baseUrl` and `url`,
29+ * - if `url` is absolute (it has a scheme: 'http://', 'https://'), the `url` is returned (ignoring the `baseUrl`)
30+ *
31+ * @param {string } baseUrl
32+ * @param {string } url
33+ * @returns {string } the resolved URL
34+ */
1535 resolve ( baseUrl : string , url : string ) : string {
1636 if ( isBlank ( baseUrl ) ) {
1737 DOM . resolveAndSetHref ( UrlResolver . a , url , null ) ;
@@ -21,6 +41,11 @@ export class UrlResolver {
2141 if ( isBlank ( url ) || url == '' ) return baseUrl ;
2242
2343 if ( url [ 0 ] == '/' ) {
44+ // The `HTMLLinkElement` does not allow resolving this case (the `url` would be interpreted as relative):
45+ // - `baseUrl` = 'http://www.foo.com/base'
46+ // - `url` = '/absolute/path/to/here'
47+ // - the result would be 'http://www.foo.com/base/absolute/path/to/here' while 'http://www.foo.com/absolute/path/to/here'
48+ // is expected (without the 'base' segment).
2449 throw new BaseException ( `Could not resolve the url ${ url } from ${ baseUrl } ` ) ;
2550 }
2651
0 commit comments