Change the parseQueryString function to return a Map rather than an Object (issue 13829)

Even though the code as-is *should* be safe, given that we're using an Object with a `null` prototype, it cannot hurt to change this to a Map to prevent any issues (since we're parsing unknown and potentially unsafe data).

Overall I also think that these changes improve the `parseQueryString` call-sites, since we now have a proper way of checking for the existence of a particular key (and don't have to use `in` which stringifies the keys in the Object).

This patch also changes the default, when no `value` exists, from `null` to an empty string since the use of `decodeURIComponent` currently can modify the value in a somewhat surprising way (at least to me).
Note how `decodeURIComponent(null) === "null"` which is unlikely to be what you actually want, whereas `decodeURIComponent("") === ""` which seems much more helpful.
This commit is contained in:
Jonas Jenwald 2021-07-31 22:15:30 +02:00
parent 222c9e7e84
commit 4ab4efd42f
4 changed files with 47 additions and 42 deletions

View file

@ -544,8 +544,8 @@ class PDFHistory {
const hash = unescape(getCurrentHash()).substring(1);
const params = parseQueryString(hash);
const nameddest = params.nameddest || "";
let page = params.page | 0;
const nameddest = params.get("nameddest") || "";
let page = params.get("page") | 0;
if (!this._isValidPage(page) || (checkNameddest && nameddest.length > 0)) {
page = null;
@ -753,7 +753,7 @@ function isDestHashesEqual(destHash, pushHash) {
if (destHash === pushHash) {
return true;
}
const { nameddest } = parseQueryString(destHash);
const nameddest = parseQueryString(destHash).get("nameddest");
if (nameddest === pushHash) {
return true;
}