From 8daee004b1a861e8b31a7e486fab970ab789ce93 Mon Sep 17 00:00:00 2001 From: tdurieux Date: Thu, 9 Sep 2021 00:32:03 +0200 Subject: [PATCH] fix: fix relative to abs url --- public/script/utils.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/script/utils.js b/public/script/utils.js index 2be501e..b96d609 100644 --- a/public/script/utils.js +++ b/public/script/utils.js @@ -8,6 +8,7 @@ function urlRel2abs(url) { return url; //Url is already absolute } var base_url = location.href.match(/^(.+)\/?(?:#.+)?$/)[0] + "/"; + if (url.substring(0, 2) == "//") return location.protocol + url; else if (url.charAt(0) == "/") return location.protocol + "//" + location.host + url; @@ -17,17 +18,17 @@ function urlRel2abs(url) { else url = "../" + url; url = base_url + url; - var i = 0; - while (/\/\.\.\//.test((url = url.replace(/[^\/]+\/+\.\.\//g, "")))); + while (/\/\.\.\//.test((url = url.replace(/[^\/]+\/+\.\.\//g, "")))); /* Escape certain characters to prevent XSS */ url = url .replace(/\.$/, "") - .replace(/\/\./g, "") + .replace(/\/\.\//g, "") .replace(/"/g, "%22") .replace(/'/g, "%27") .replace(//g, "%3E"); + return url; }