Skip to content

Commit ed08428

Browse files
committed
feat: also update the client isExternal check
1 parent 0a8deed commit ed08428

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/core/fetch/index.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,19 @@ function loadNested(path, qs, file, next, vm, first) {
2020
).then(next, _ => loadNested(path, qs, file, next, vm));
2121
}
2222

23+
// Borrowed from https://j11y.io/snippets/getting-a-fully-qualified-url.
24+
function qualifyURL(url){
25+
var img = document.createElement('img');
26+
img.src = url; // set string url
27+
url = img.src; // get qualified url
28+
img.src = ''; // prevent the server request
29+
return url;
30+
}
31+
2332
function isExternal(url) {
24-
let match = url.match(
25-
/^([^:\/?#]+:)?(?:\/\/([^\/?#]*))?([^?#]+)?(\?[^#]*)?(#.*)?/
26-
);
27-
if (
28-
typeof match[1] === 'string' &&
29-
match[1].length > 0 &&
30-
match[1].toLowerCase() !== location.protocol
31-
) {
32-
return true;
33-
}
34-
if (
35-
typeof match[2] === 'string' &&
36-
match[2].length > 0 &&
37-
match[2].replace(
38-
new RegExp(
39-
':(' + { 'http:': 80, 'https:': 443 }[location.protocol] + ')?$'
40-
),
41-
''
42-
) !== location.host
43-
) {
44-
return true;
45-
}
46-
return false;
33+
url = qualifyURL(url)
34+
url = new URL(url)
35+
return url.origin !== location.origin
4736
}
4837

4938
export function fetchMixin(proto) {

0 commit comments

Comments
 (0)