Skip to content

Commit 4f45948

Browse files
authored
tests/common-utils: parse query string w/ URLSearchParams (#8779)
* previous parsing was manual * switch from using `document.location` to more-standard `window.location` * currently this PR re-implements surprising details of old implementation Original mapping of empty strings to `true` looks like it was introduced in 2f7b57b.
1 parent 775b2e1 commit 4f45948

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

tests/common-utils.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ commonUtils.params = function () {
1414
if (commonUtils.isNode()) {
1515
return process.env;
1616
}
17-
var paramStr = document.location.search.slice(1);
18-
return paramStr.split('&').reduce(function (acc, val) {
19-
if (!val) {
20-
return acc;
21-
}
22-
var tmp = val.split('=');
23-
acc[tmp[0]] = decodeURIComponent(tmp[1]) || true;
24-
return acc;
25-
}, {});
17+
const usp = new URLSearchParams(window.location.search);
18+
const params = {};
19+
for (const [k, v] of usp) {
20+
// This preserves previous behaviour: an empty value is re-mapped to
21+
// `true`. This is surprising, and differs from the handling of env vars in
22+
// node (see above).
23+
params[k] = v || true;
24+
}
25+
return params;
2626
};
2727

2828
commonUtils.adapters = function () {

0 commit comments

Comments
 (0)