Skip to content

Commit

Permalink
Use anchor instead of URL for relative to absolute path convertion
Browse files Browse the repository at this point in the history
Use an anchor element's href attribute to convert relative paths to absolute paths
  • Loading branch information
hbirler committed Jul 8, 2021
1 parent 2fbc2f8 commit 2647bfb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/runtime/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 2647bfb

Please sign in to comment.