mirror of
https://github.com/Feodor2/Mypal68.git
synced 2025-06-23 01:05:49 -04:00
18 lines
388 B
JavaScript
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 : "";
|
|
}
|