From 2647bfbbee3bd21bd5e7b67f0d1ef2081abf3115 Mon Sep 17 00:00:00 2001 From: Altan Birler Date: Thu, 8 Jul 2021 22:03:25 +0200 Subject: [PATCH] Use anchor instead of URL for relative to absolute path convertion Use an anchor element's href attribute to convert relative paths to absolute paths --- src/runtime/internal/utils.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/runtime/internal/utils.ts b/src/runtime/internal/utils.ts index 84bf75b0c0..0de03f4b12 100644 --- a/src/runtime/internal/utils.ts +++ b/src/runtime/internal/utils.ts @@ -40,8 +40,16 @@ export function safe_not_equal(a, b) { return a != a ? b == b : a !== b || ((a && typeof a === 'object') || typeof a === 'function'); } -export function src_url_equal(a, b) { - return new URL(a, window.location.origin).href === (new URL(b, window.location.origin)).href; +const relative_to_absolute = (function() { + const anchor = document.createElement('a'); + return function(url) { + anchor.href = url; + return anchor.href; + }; +})(); + +export function src_url_equal(element_src, url) { + return element_src === relative_to_absolute(url); } export function not_equal(a, b) {