2018-05-03 06:45:14 +00:00
|
|
|
// @flow
|
2020-06-20 20:59:15 +00:00
|
|
|
import { parseDomain } from "../../shared/utils/domains";
|
2018-11-19 02:43:11 +00:00
|
|
|
|
2021-01-16 19:12:10 +00:00
|
|
|
export function isInternalUrl(href: string) {
|
2020-06-20 20:59:15 +00:00
|
|
|
if (href[0] === "/") return true;
|
2018-05-03 06:45:14 +00:00
|
|
|
|
2019-02-09 09:17:54 +00:00
|
|
|
const outline = parseDomain(window.location.href);
|
2018-11-19 02:43:11 +00:00
|
|
|
const parsed = parseDomain(href);
|
2020-07-17 04:26:23 +00:00
|
|
|
|
2018-11-19 02:43:11 +00:00
|
|
|
if (
|
|
|
|
parsed &&
|
|
|
|
outline &&
|
2019-02-09 09:17:54 +00:00
|
|
|
parsed.subdomain === outline.subdomain &&
|
2018-11-19 02:43:11 +00:00
|
|
|
parsed.domain === outline.domain &&
|
|
|
|
parsed.tld === outline.tld
|
|
|
|
) {
|
|
|
|
return true;
|
2018-05-03 06:45:14 +00:00
|
|
|
}
|
2018-11-19 02:43:11 +00:00
|
|
|
|
|
|
|
return false;
|
2018-05-03 06:45:14 +00:00
|
|
|
}
|
2021-01-16 19:12:10 +00:00
|
|
|
|
2021-02-20 21:03:41 +00:00
|
|
|
export function decodeURIComponentSafe(text: string) {
|
|
|
|
return text
|
|
|
|
? decodeURIComponent(text.replace(/%(?![0-9][0-9a-fA-F]+)/g, "%25"))
|
|
|
|
: text;
|
|
|
|
}
|