Bug 1801716 - Handle missing hostname variables; r=nordzilla

The HOST_NAME could be undefined if the URL is not valid and throws. The
broader functions that use it would still be defined due to hoisting.

Differential Revision: https://phabricator.services.mozilla.com/D164462
This commit is contained in:
Greg Tatum 2022-12-13 15:18:51 +00:00
Родитель 4842dfc9f6
Коммит 0515d6a08f
1 изменённых файлов: 11 добавлений и 3 удалений

Просмотреть файл

@ -24,8 +24,16 @@ const { parse, pemToDER } = globalThis.certDecoderInitializer(
const formatter = new Intl.DateTimeFormat();
const HOST_NAME =
new URL(RPMGetInnerMostURI(document.location.href)).hostname ?? "";
const HOST_NAME = getHostName();
function getHostName() {
try {
return new URL(RPMGetInnerMostURI(document.location.href)).hostname;
} catch (error) {
console.error("Could not parse URL", error);
}
return "";
}
// Used to check if we have a specific localized message for an error.
const KNOWN_ERROR_TITLE_IDS = new Set([
@ -300,7 +308,7 @@ function initPage() {
document.getElementById("errorShortDesc").hidden = true;
document.l10n.setAttributes(longDesc, "csp-xfo-blocked-long-desc", {
hostname: document.location.hostname, // FIXME - should this be HOST_NAME?
hostname: document.location.hostname ?? "", // FIXME - should this be HOST_NAME?
});
longDesc = null;