Mypal68/browser/components/newtab/content-src/asrouter/template-utils.js
2022-04-16 07:41:55 +03:00

18 lines
388 B
JavaScript

export function safeURI(url) {
if (!url) {
return "";
}
const {protocol} = new URL(url);
const isAllowed = [
"http:",
"https:",
"data:",
"resource:",
"chrome:",
].includes(protocol);
if (!isAllowed) {
console.warn(`The protocol ${protocol} is not allowed for template URLs.`); // eslint-disable-line no-console
}
return isAllowed ? url : "";
}