Comparing version 2.2.4 to 2.2.5
## [**2.2.4**](https://github.com/hapijs/qs/issues?milestone=13&state=closed) | ||
- [**#38**](https://github.com/hapijs/qs/issues/38) how to handle object keys beginning with a number | ||
## [**2.2.3**](https://github.com/hapijs/qs/issues?milestone=12&state=closed) | ||
@@ -3,0 +6,0 @@ - [**#37**](https://github.com/hapijs/qs/issues/37) parser discards first empty value in array |
@@ -34,8 +34,12 @@ // Load modules | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']')); | ||
} | ||
if (typeof obj === 'undefined') { | ||
return values; | ||
} | ||
var objKeys = Object.keys(obj); | ||
for (var i = 0, il = objKeys.length; i < il; ++i) { | ||
var key = objKeys[i]; | ||
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']')); | ||
} | ||
return values; | ||
@@ -52,6 +56,6 @@ }; | ||
for (var key in obj) { | ||
if (obj.hasOwnProperty(key)) { | ||
keys = keys.concat(internals.stringify(obj[key], key)); | ||
} | ||
var objKeys = Object.keys(obj); | ||
for (var i = 0, il = objKeys.length; i < il; ++i) { | ||
var key = objKeys[i]; | ||
keys = keys.concat(internals.stringify(obj[key], key)); | ||
} | ||
@@ -58,0 +62,0 @@ |
@@ -29,25 +29,16 @@ // Load modules | ||
if (Array.isArray(source)) { | ||
for (var i = 0, il = source.length; i < il; ++i) { | ||
if (typeof source[i] !== 'undefined') { | ||
if (typeof target[i] === 'object') { | ||
target[i] = exports.merge(target[i], source[i]); | ||
} | ||
else { | ||
target[i] = source[i]; | ||
} | ||
} | ||
} | ||
if (typeof source !== 'object') { | ||
target.push(source); | ||
return target; | ||
} | ||
if (typeof target !== 'object') { | ||
target = [target].concat(source); | ||
return target; | ||
} | ||
if (Array.isArray(target)) { | ||
if (typeof source !== 'object') { | ||
target.push(source); | ||
return target; | ||
} | ||
else { | ||
target = exports.arrayToObject(target); | ||
} | ||
if (Array.isArray(target) && | ||
!Array.isArray(source)) { | ||
target = exports.arrayToObject(target); | ||
} | ||
@@ -60,14 +51,7 @@ | ||
if (value && | ||
typeof value === 'object') { | ||
if (!target[key]) { | ||
target[key] = value; | ||
} | ||
else { | ||
target[key] = exports.merge(target[key], value); | ||
} | ||
if (!target[key]) { | ||
target[key] = value; | ||
} | ||
else { | ||
target[key] = value; | ||
target[key] = exports.merge(target[key], value); | ||
} | ||
@@ -135,8 +119,11 @@ } | ||
if (typeof Buffer !== 'undefined') { | ||
return Buffer.isBuffer(obj); | ||
} | ||
else { | ||
if (obj === null || | ||
typeof obj === 'undefined') { | ||
return false; | ||
} | ||
return !!(obj.constructor && | ||
obj.constructor.isBuffer && | ||
obj.constructor.isBuffer(obj)); | ||
}; |
{ | ||
"name": "qs", | ||
"version": "2.2.4", | ||
"version": "2.2.5", | ||
"description": "A querystring parser that supports nesting and arrays, with a depth limit", | ||
@@ -22,3 +22,2 @@ "homepage": "https://github.com/hapijs/qs", | ||
], | ||
"author": "Nathan LaFreniere <quitlahok@gmail.com>", | ||
"licenses": [ | ||
@@ -25,0 +24,0 @@ { |
@@ -16,4 +16,2 @@ // Load modules | ||
var expect = Lab.expect; | ||
var before = lab.before; | ||
var after = lab.after; | ||
var describe = lab.experiment; | ||
@@ -23,3 +21,3 @@ var it = lab.test; | ||
describe('#parse', function () { | ||
describe('parse()', function () { | ||
@@ -87,2 +85,13 @@ it('parses a simple string', function (done) { | ||
it('parses a mix of simple and explicit arrays', function (done) { | ||
expect(Qs.parse('a=b&a[]=c')).to.deep.equal({ a: ['b', 'c'] }); | ||
expect(Qs.parse('a[]=b&a=c')).to.deep.equal({ a: ['b', 'c'] }); | ||
expect(Qs.parse('a[0]=b&a=c')).to.deep.equal({ a: ['b', 'c'] }); | ||
expect(Qs.parse('a=b&a[0]=c')).to.deep.equal({ a: ['b', 'c'] }); | ||
expect(Qs.parse('a[1]=b&a=c')).to.deep.equal({ a: ['b', 'c'] }); | ||
expect(Qs.parse('a=b&a[1]=c')).to.deep.equal({ a: ['b', 'c'] }); | ||
done(); | ||
}); | ||
it('parses a nested array', function (done) { | ||
@@ -89,0 +98,0 @@ |
@@ -16,4 +16,2 @@ // Load modules | ||
var expect = Lab.expect; | ||
var before = lab.before; | ||
var after = lab.after; | ||
var describe = lab.experiment; | ||
@@ -23,3 +21,3 @@ var it = lab.test; | ||
describe('#stringify', function () { | ||
describe('stringify()', function () { | ||
@@ -75,2 +73,21 @@ it('stringifies a querystring object', function (done) { | ||
it('stringifies an empty object', function (done) { | ||
var obj = Object.create(null); | ||
obj.a = 'b'; | ||
expect(Qs.stringify(obj)).to.equal('a=b'); | ||
done(); | ||
}); | ||
it('stringifies an object with an empty object as a child', function (done) { | ||
var obj = { | ||
a: Object.create(null) | ||
}; | ||
obj.a.b = 'c'; | ||
expect(Qs.stringify(obj)).to.equal('a%5Bb%5D=c'); | ||
done(); | ||
}); | ||
it('drops keys with a value of undefined', function (done) { | ||
@@ -77,0 +94,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
36195
651
2