Fix isInternalUrl for subdomain support
Refactor / reduce plumbing
This commit is contained in:
@@ -1,12 +1,19 @@
|
||||
// @flow
|
||||
import parseDomain from 'parse-domain';
|
||||
|
||||
export default function isInternalUrl(href: string) {
|
||||
if (href[0] === '/') return true;
|
||||
|
||||
try {
|
||||
const outline = new URL(BASE_URL);
|
||||
const parsed = new URL(href);
|
||||
return parsed.hostname === outline.hostname;
|
||||
} catch (err) {
|
||||
return false;
|
||||
const outline = parseDomain(BASE_URL);
|
||||
const parsed = parseDomain(href);
|
||||
if (
|
||||
parsed &&
|
||||
outline &&
|
||||
parsed.domain === outline.domain &&
|
||||
parsed.tld === outline.tld
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user