From 8ebca50595842a6a3e2419385ad050169c03ca81 Mon Sep 17 00:00:00 2001 From: Evan Lemke Date: Tue, 5 Nov 2024 13:42:29 -0700 Subject: [PATCH] support duplicate querystring keys `/my-page?foo=bar&foo=bar` results in an error caused by calling `Object.assign(obj[key], val)` on an existing string > Uncaught TypeError: Cannot assign to read only property '0' of object '[object String]' Instead of erroring, ignore duplicates of type `string` --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 2e22d60..be81484 100644 --- a/src/utils.js +++ b/src/utils.js @@ -185,7 +185,7 @@ export function parseQuery(str = '', { decode = decodeURIComponent } = {}) { let o = parseKeys(key, val); obj = Object.keys(o).reduce((obj, key) => { const val = prefs.convertTypes ? convertType(o[key]) : o[key]; - if (obj[key]) { + if (obj[key] && typeof obj[key] != 'string') { Array.isArray(obj[key]) ? (obj[key] = obj[key].concat(val)) : Object.assign(obj[key], val);