aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/utils.js
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2023-02-08 00:08:44 +0800
committerGitHub <noreply@github.com>2023-02-08 00:08:44 +0800
commit2c6cc0b8c982b3d49a5b208f75e15b2269584312 (patch)
tree09746485be5f6c534082585f137c921d6a34ab75 /web_src/js/utils.js
parentd5fa2e7510844ad092804b7c11bf6847f7c4e45d (diff)
downloadgitea-2c6cc0b8c982b3d49a5b208f75e15b2269584312.tar.gz
gitea-2c6cc0b8c982b3d49a5b208f75e15b2269584312.zip
Fix links for the menus in the view file page (#22795)
Diffstat (limited to 'web_src/js/utils.js')
-rw-r--r--web_src/js/utils.js14
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}`;
}