Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

ensure objects are created when appropo #31

Merged
merged 1 commit into from

2 participants

@aheckmann

No description provided.

@tj tj merged commit 18f06b0 into tj:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 8, 2012
  1. @aheckmann
This page is out of date. Refresh to see the latest.
Showing with 9 additions and 5 deletions.
  1. +4 −4 lib/querystring.js
  2. +5 −1 test/parse.js
View
8 lib/querystring.js
@@ -21,7 +21,7 @@ var toString = Object.prototype.toString;
* Cache non-integer test regexp.
*/
-var notint = /^[^0-9]+$/;
+var isint = /^[0-9]+$/;
function promote(parent, key) {
if (parent[key].length == 0) return parent[key] = {};
@@ -58,11 +58,11 @@ function parse(parts, parent, key, val) {
// prop
} else if (~part.indexOf(']')) {
part = part.substr(0, part.length - 1);
- if(notint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
+ if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
parse(parts, obj, part, val);
// key
} else {
- if(notint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
+ if (!isint.test(part) && Array.isArray(obj)) obj = promote(parent, key);
parse(parts, obj, part, val);
}
}
@@ -80,7 +80,7 @@ function merge(parent, key, val){
parse(parts, parent, 'base', val);
// optimize
} else {
- if (notint.test(key) && Array.isArray(parent.base)) {
+ if (!isint.test(key) && Array.isArray(parent.base)) {
var t = {};
for (var k in parent.base) t[k] = parent.base[k];
parent.base = t;
View
6 test/parse.js
@@ -91,8 +91,12 @@ module.exports = {
qs.parse('user[name][first]=tj&user[name][first]=TJ')
.should.eql({ user: { name: { first: ['tj', 'TJ'] }}});
+
+ var o = qs.parse('existing[fcbaebfecc][name][last]=tj')
+ o.should.eql({ existing: { 'fcbaebfecc': { name: { last: 'tj' }}}})
+ Array.isArray(o.existing).should.be.false;
},
-
+
'test right-hand brackets': function(){
qs.parse('pets=["tobi"]')
.should.eql({ pets: '["tobi"]' });
Something went wrong with that request. Please try again.