feat: also update the client isExternal check

This commit is contained in:
Joe Pea 2020-04-26 15:46:56 -07:00
parent 0a8deed072
commit ed08428638

View File

@ -20,30 +20,19 @@ function loadNested(path, qs, file, next, vm, first) {
).then(next, _ => loadNested(path, qs, file, next, vm));
}
// Borrowed from https://j11y.io/snippets/getting-a-fully-qualified-url.
function qualifyURL(url){
var img = document.createElement('img');
img.src = url; // set string url
url = img.src; // get qualified url
img.src = ''; // prevent the server request
return url;
}
function isExternal(url) {
let match = url.match(
/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
);
if (
typeof match[1] === 'string' &&
match[1].length > 0 &&
match[1].toLowerCase() !== location.protocol
) {
return true;
}
if (
typeof match[2] === 'string' &&
match[2].length > 0 &&
match[2].replace(
new RegExp(
':(' + { 'http:': 80, 'https:': 443 }[location.protocol] + ')?$'
),
''
) !== location.host
) {
return true;
}
return false;
url = qualifyURL(url)
url = new URL(url)
return url.origin !== location.origin
}
export function fetchMixin(proto) {