Change the hashParameters function to return a Map rather than an Object (issue 13862)

This patch (basically) mirrors the implementation in PR 13831, to get rid of the "Remote property injection" warning.
This commit is contained in:
Jonas Jenwald 2021-08-04 14:22:42 +02:00
parent 5dfdfbc70b
commit 39663e730e

View File

@ -52,24 +52,26 @@ window.onload = function () {
} }
function hashParameters() { function hashParameters() {
const result = {}; const query = window.location.hash.substring(1);
const params = window.location.hash.substring(1).split(/[&;]/); const params = new Map();
for (let i = 0; i < params.length; i++) { for (const part of query.split(/[&;]/)) {
const parts = params[i].split("="); const param = part.split("="),
result[parts[0]] = unescape(unescape(parts[1])); key = param[0].toLowerCase(),
value = param.length > 1 ? param[1] : "";
params.set(decodeURIComponent(key), decodeURIComponent(value));
} }
return result; return params;
} }
function load() { function load() {
gPhases = [ID("entry"), ID("loading"), ID("viewer")]; gPhases = [ID("entry"), ID("loading"), ID("viewer")];
buildMag(); buildMag();
const params = hashParameters(); const params = hashParameters();
if (params.log) { if (params.has("log")) {
ID("logEntry").value = params.log; ID("logEntry").value = params.get("log");
logPasted(); logPasted();
} else if (params.web) { } else if (params.has("web")) {
loadFromWeb(params.web); loadFromWeb(params.get("web"));
} }
ID("logEntry").focus(); ID("logEntry").focus();
} }