Backed out changeset 425f70fa7e5a (bug 1878556) Backed out changeset 2ab3a28f5c04 (bug 1878556) Backed out changeset fb2e02682c8c (bug 1878556) Backed out changeset 2fc5e630568e (bug 1878554) Backed out changeset 78839d5841b4 (bug 1878554) Backed out changeset e0ab31d2de1b (bug 1878554) Backed out changeset 4eb59e4ebafa (bug 1878554) Backed out changeset ab1e077d3f84 (bug 1878554) Backed out changeset ef999f293e3e (bug 1878553) Backed out changeset cf49920cb1ad (bug 1878553) Backed out changeset 95f0fce63726 (bug 1878553)
23 lines
605 B
JavaScript
23 lines
605 B
JavaScript
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
export function safeURI(url) {
|
|
if (!url) {
|
|
return "";
|
|
}
|
|
const { protocol } = new URL(url);
|
|
const isAllowed = [
|
|
"http:",
|
|
"https:",
|
|
"data:",
|
|
"resource:",
|
|
"chrome:",
|
|
].includes(protocol);
|
|
if (!isAllowed) {
|
|
// eslint-disable-next-line no-console
|
|
console.warn(`The protocol ${protocol} is not allowed for template URLs.`);
|
|
}
|
|
return isAllowed ? url : "";
|
|
}
|