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 +5 -0
- package/lib/querystring.js +5 -5
- package/package.json +1 -1
- package/test/parse.js +5 -1
package/History.md
CHANGED
package/lib/querystring.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* Library version.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
exports.version = '0.4.
|
|
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
|
|
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(
|
|
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(
|
|
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 (
|
|
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
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"]' });
|