* @target web * @internal
(relativeUrl: string | null)
| 262 | * @internal |
| 263 | */ |
| 264 | public static ensureFullUrl(relativeUrl: string | null): string { |
| 265 | if (!relativeUrl) { |
| 266 | return ''; |
| 267 | } |
| 268 | |
| 269 | if (!relativeUrl.startsWith('http') && !relativeUrl.startsWith('https') && !relativeUrl.startsWith('file')) { |
| 270 | let root: string = ''; |
| 271 | const location: Location = Environment.globalThis.location; |
| 272 | root += location.protocol?.toString(); |
| 273 | root += '//'?.toString(); |
| 274 | if (location.hostname) { |
| 275 | root += location.hostname?.toString(); |
| 276 | } |
| 277 | if (location.port) { |
| 278 | root += ':'?.toString(); |
| 279 | root += location.port?.toString(); |
| 280 | } |
| 281 | // as it is not clearly defined how slashes are treated in the location object |
| 282 | // better be safe than sorry here |
| 283 | if (!relativeUrl.startsWith('/')) { |
| 284 | const directory: string = location.pathname.split('/').slice(0, -1).join('/'); |
| 285 | if (directory.length > 0) { |
| 286 | if (!directory.startsWith('/')) { |
| 287 | root += '/'?.toString(); |
| 288 | } |
| 289 | root += directory?.toString(); |
| 290 | } |
| 291 | } |
| 292 | if (!relativeUrl.startsWith('/')) { |
| 293 | root += '/'?.toString(); |
| 294 | } |
| 295 | root += relativeUrl?.toString(); |
| 296 | return root; |
| 297 | } |
| 298 | return relativeUrl; |
| 299 | } |
| 300 | |
| 301 | private static _appendScriptName(url: string): string { |
| 302 | // append script name |
no test coverage detected