qs 0.4.1 → 0.4.2

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.4.2 / 2012-02-08
3
+ ==================
4
+
5
+ * Fixed: ensure objects are created when appropriate not arrays [aheckmann]
6
+
2
7
  0.4.1 / 2012-01-26
3
8
  ==================
4
9
 
@@ -9,7 +9,7 @@
9
9
  * Library version.
10
10
  */
11
11
 
12
- exports.version = '0.4.1';
12
+ exports.version = '0.4.2';
13
13
 
14
14
  /**
15
15
  * Object#toString() ref for stringify().
@@ -21,7 +21,7 @@ var toString = Object.prototype.toString;
21
21
  * Cache non-integer test regexp.
22
22
  */
23
23
 
24
- var notint = /^[^0-9]+$/;
24
+ var isint = /^[0-9]+$/;
25
25
 
26
26
  function promote(parent, key) {
27
27
  if (parent[key].length == 0) return parent[key] = {};
@@ -58,11 +58,11 @@ function parse(parts, parent, key, val) {
58
58
  // prop
59
59
  } else if (~part.indexOf(']')) {
60
60
  part = part.substr(0, part.length - 1);
61
- if(notint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
61
+ if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
62
62
  parse(parts, obj, part, val);
63
63
  // key
64
64
  } else {
65
- if(notint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
65
+ if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
66
66
  parse(parts, obj, part, val);
67
67
  }
68
68
  }
@@ -80,7 +80,7 @@ function merge(parent, key, val){
80
80
  parse(parts, parent, 'base', val);
81
81
  // optimize
82
82
  } else {
83
- if (notint.test(key) && Array.isArray(parent.base)) {
83
+ if (!isint.test(key) && Array.isArray(parent.base)) {
84
84
  var t = {};
85
85
  for (var k in parent.base) t[k] = parent.base[k];
86
86
  parent.base = t;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "qs",
3
3
  "description": "querystring parser",
4
- "version": "0.4.1",
4
+ "version": "0.4.2",
5
5
  "repository": {
6
6
  "type" : "git",
7
7
  "url" : "git://github.com/visionmedia/node-querystring.git"
package/test/parse.js CHANGED
@@ -91,8 +91,12 @@ module.exports = {
91
91
 
92
92
  qs.parse('user[name][first]=tj&user[name][first]=TJ')
93
93
  .should.eql({ user: { name: { first: ['tj', 'TJ'] }}});
94
+
95
+ var o = qs.parse('existing[fcbaebfecc][name][last]=tj')
96
+ o.should.eql({ existing: { 'fcbaebfecc': { name: { last: 'tj' }}}})
97
+ Array.isArray(o.existing).should.be.false;
94
98
  },
95
-
99
+
96
100
  'test right-hand brackets': function(){
97
101
  qs.parse('pets=["tobi"]')
98
102
  .should.eql({ pets: '["tobi"]' });