| 215 | |
| 216 | // https://github.com/angular/angular.js/blob/864c7f0/src/ng/urlUtils.js#L60 |
| 217 | parse(url: string, base?: string) { |
| 218 | try { |
| 219 | // Safari 12 throws an error when the URL constructor is called with an undefined base. |
| 220 | const parsed = !base ? new URL(url) : new URL(url, base); |
| 221 | return { |
| 222 | href: parsed.href, |
| 223 | protocol: parsed.protocol ? parsed.protocol.replace(/:$/, '') : '', |
| 224 | host: parsed.host, |
| 225 | search: parsed.search ? parsed.search.replace(/^\?/, '') : '', |
| 226 | hash: parsed.hash ? parsed.hash.replace(/^#/, '') : '', |
| 227 | hostname: parsed.hostname, |
| 228 | port: parsed.port, |
| 229 | pathname: parsed.pathname.charAt(0) === '/' ? parsed.pathname : '/' + parsed.pathname, |
| 230 | }; |
| 231 | } catch (e) { |
| 232 | throw new Error(`Invalid URL (${url}) with base (${base})`); |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | function _stripIndexHtml(url: string): string { |