diff options
author | Yoshiya Hinosawa <stibium121@gmail.com> | 2020-11-03 02:58:29 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-02 18:58:29 +0100 |
commit | 397fec63d1bacabd2b8e48bd30a1727003a7a72b (patch) | |
tree | c89ab8dbd5581836ce3290eb7df54cf1983198c4 /op_crates/web/11_url.js | |
parent | c5611636fb03ce71f50a9bca958c79d23b55be00 (diff) |
fix(op_crates/web): fix URLSearchParams, malformed url handling (#8092)
Co-authored-by: Evan <c4t@tuta.io>
Diffstat (limited to 'op_crates/web/11_url.js')
-rw-r--r-- | op_crates/web/11_url.js | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/op_crates/web/11_url.js b/op_crates/web/11_url.js index f2d12f5be..d60f9769a 100644 --- a/op_crates/web/11_url.js +++ b/op_crates/web/11_url.js @@ -37,7 +37,16 @@ } function decodeSearchParam(p) { - return decodeURIComponent(p.replace(/\+/g, " ")); + const s = p.replaceAll("+", " "); + const decoder = new TextDecoder(); + + return s.replace(/(%[0-9a-f]{2})+/gi, (matched) => { + const buf = new Uint8Array(Math.ceil(matched.length / 3)); + for (let i = 0, offset = 0; i < matched.length; i += 3, offset += 1) { + buf[offset] = parseInt(matched.slice(i + 1, i + 3), 16); + } + return decoder.decode(buf); + }); } const urls = new WeakMap(); |