Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix encoded =. Closes #43

  • Loading branch information...
commit 9d829d306cd000b69e3c19c4f270fb011ef21770 1 parent 6ba94ee
@tj authored
Showing with 17 additions and 10 deletions.
  1. +17 −7 lib/querystring.js
  2. +0 −3  test/parse.js
View
24 lib/querystring.js
@@ -99,12 +99,6 @@ function parseString(str){
return String(str)
.split('&')
.reduce(function(ret, pair){
- try{
- pair = decodeURIComponent(pair.replace(/\+/g, ' '));
- } catch(e) {
- // ignore
- }
-
var eql = pair.indexOf('=')
, brace = lastBraceInKey(pair)
, key = pair.substr(0, brace || eql)
@@ -114,7 +108,7 @@ function parseString(str){
// ?foo
if ('' == key) key = pair, val = '';
- return merge(ret, key, val);
+ return merge(ret, decode(key), decode(val));
}, { base: {} }).base;
}
@@ -250,3 +244,19 @@ function lastBraceInKey(str) {
if ('=' == c && !brace) return i;
}
}
+
+/**
+ * Decode `str`.
+ *
+ * @param {String} str
+ * @return {String}
+ * @api private
+ */
+
+function decode(str) {
+ try {
+ return decodeURIComponent(str.replace(/\+/g, ' '));
+ } catch (err) {
+ return str;
+ }
+}
View
3  test/parse.js
@@ -28,9 +28,6 @@ describe('qs.parse()', function(){
expect(qs.parse('foo=bar'))
.to.eql({ foo: 'bar' });
- expect(qs.parse('foo%3Dbar=baz'))
- .to.eql({ foo: 'bar=baz' });
-
expect(qs.parse(' foo = bar = baz '))
.to.eql({ ' foo ': ' bar = baz ' });
Please sign in to comment.
Something went wrong with that request. Please try again.