diff options
author | Tristan Berger <tristan.berger@gmail.com> | 2014-08-26 04:39:25 -0400 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2014-08-27 13:49:16 +0400 |
commit | 0f2956192c51abc6fc8311102b004f1e975e157f (patch) | |
tree | 1370c2bafcf956f1b14e232d0a0e926f8bd48a6a /lib/querystring.js | |
parent | f39e608c6eb11c91839ea4661caece1f89f1b12f (diff) | |
download | android-node-v8-0f2956192c51abc6fc8311102b004f1e975e157f.tar.gz android-node-v8-0f2956192c51abc6fc8311102b004f1e975e157f.tar.bz2 android-node-v8-0f2956192c51abc6fc8311102b004f1e975e157f.zip |
querystring: fix unescape override
Documentation states that `querystring.unescape` may be overridden to
replace unescaper during parsing. However, the function was only
being used as a fallback for when the native decoder throws (on a
malformed URL). This patch moves the call to the native function and
the try/catch around it into querystring.unescape then has the parser
always invoke it, so that an override will always be used.
Fixes #4055
Reviewed-By: Fedor Indutny <fedor@indutny.com>
Diffstat (limited to 'lib/querystring.js')
-rw-r--r-- | lib/querystring.js | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/querystring.js b/lib/querystring.js index 0ab739a522..f8c79216d3 100644 --- a/lib/querystring.js +++ b/lib/querystring.js @@ -105,7 +105,11 @@ QueryString.unescapeBuffer = function(s, decodeSpaces) { QueryString.unescape = function(s, decodeSpaces) { - return QueryString.unescapeBuffer(s, decodeSpaces).toString(); + try { + return decodeURIComponent(s); + } catch (e) { + return QueryString.unescapeBuffer(s, decodeSpaces).toString(); + } }; @@ -193,13 +197,8 @@ QueryString.parse = QueryString.decode = function(qs, sep, eq, options) { vstr = ''; } - try { - k = decodeURIComponent(kstr); - v = decodeURIComponent(vstr); - } catch (e) { - k = QueryString.unescape(kstr, true); - v = QueryString.unescape(vstr, true); - } + k = QueryString.unescape(kstr, true); + v = QueryString.unescape(vstr, true); if (!hasOwnProperty(obj, k)) { obj[k] = v; |