diff options
Diffstat (limited to 'web_src/js/utils.js')
-rw-r--r-- | web_src/js/utils.js | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/web_src/js/utils.js b/web_src/js/utils.js index b9cd69e15a..c7624404c7 100644 --- a/web_src/js/utils.js +++ b/web_src/js/utils.js @@ -134,9 +134,15 @@ export function convertImage(blob, mime) { }); } -export function toAbsoluteUrl(relUrl) { - if (relUrl.startsWith('http://') || relUrl.startsWith('https://')) { - return relUrl; +export function toAbsoluteUrl(url) { + if (url.startsWith('http://') || url.startsWith('https://')) { + return url; } - return `${window.location.origin}${relUrl}`; + if (url.startsWith('//')) { + return `${window.location.protocol}${url}`; // it's also a somewhat absolute URL (with the current scheme) + } + if (url && !url.startsWith('/')) { + throw new Error('unsupported url, it should either start with / or http(s)://'); + } + return `${window.location.origin}${url}`; } |