qs 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/History.md CHANGED
@@ -1,4 +1,9 @@
1
1
 
2
+ 0.5.1 / 2012-09-18
3
+ ==================
4
+
5
+ * fix encoded `=`. Closes #43
6
+
2
7
  0.5.0 / 2012-05-04
3
8
  ==================
4
9
 
package/component.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "querystring",
3
+ "description": "Querystring parser / stringifier with nesting support",
4
+ "keywords": ["querystring", "query", "parser"],
5
+ "main": "lib/querystring.js"
6
+ }
@@ -99,12 +99,6 @@ function parseString(str){
99
99
  return String(str)
100
100
  .split('&')
101
101
  .reduce(function(ret, pair){
102
- try{
103
- pair = decodeURIComponent(pair.replace(/\+/g, ' '));
104
- } catch(e) {
105
- // ignore
106
- }
107
-
108
102
  var eql = pair.indexOf('=')
109
103
  , brace = lastBraceInKey(pair)
110
104
  , key = pair.substr(0, brace || eql)
@@ -114,7 +108,7 @@ function parseString(str){
114
108
  // ?foo
115
109
  if ('' == key) key = pair, val = '';
116
110
 
117
- return merge(ret, key, val);
111
+ return merge(ret, decode(key), decode(val));
118
112
  }, { base: {} }).base;
119
113
  }
120
114
 
@@ -250,3 +244,19 @@ function lastBraceInKey(str) {
250
244
  if ('=' == c && !brace) return i;
251
245
  }
252
246
  }
247
+
248
+ /**
249
+ * Decode `str`.
250
+ *
251
+ * @param {String} str
252
+ * @return {String}
253
+ * @api private
254
+ */
255
+
256
+ function decode(str) {
257
+ try {
258
+ return decodeURIComponent(str.replace(/\+/g, ' '));
259
+ } catch (err) {
260
+ return str;
261
+ }
262
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qs",
3
3
  "description": "querystring parser",
4
- "version": "0.5.0",
4
+ "version": "0.5.1",
5
5
  "keywords": ["query string", "parser", "component"],
6
6
  "repository": {
7
7
  "type" : "git",
package/test/parse.js CHANGED
@@ -28,9 +28,6 @@ describe('qs.parse()', function(){
28
28
  expect(qs.parse('foo=bar'))
29
29
  .to.eql({ foo: 'bar' });
30
30
 
31
- expect(qs.parse('foo%3Dbar=baz'))
32
- .to.eql({ foo: 'bar=baz' });
33
-
34
31
  expect(qs.parse(' foo = bar = baz '))
35
32
  .to.eql({ ' foo ': ' bar = baz ' });
36
33
 
@@ -52,6 +49,11 @@ describe('qs.parse()', function(){
52
49
  });
53
50
  })
54
51
 
52
+ it('should support encoded = signs', function(){
53
+ expect(qs.parse('he%3Dllo=th%3Dere'))
54
+ .to.eql({ 'he=llo': 'th=ere' });
55
+ })
56
+
55
57
  it('should support nesting', function(){
56
58
  expect(qs.parse('ops[>=]=25'))
57
59
  .to.eql({ ops: { '>=': '25' }});