Skip to content

Commit

Permalink
__proto__ needed to be restored to objects stored in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
hasbro-dtplatform committed May 27, 2013
1 parent 8ed6a18 commit 687038a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 2 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function compact(obj) {

for (var i in obj) {
if (hasOwnProperty.call(obj, i)) {
ret.push(obj[i]);
ret.push(restoreProto(obj[i]));
}
}

Expand All @@ -183,10 +183,7 @@ function compact(obj) {

function restoreProto(obj) {
if (!Object.create) return obj;
if (isArray(obj)) {
obj.__proto__ = Object.prototype;
return obj;
}
if (isArray(obj)) return obj;
if (obj && 'object' != typeof obj) return obj;

for (var key in obj) {
Expand Down
4 changes: 4 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ describe('qs.parse()', function(){
expect(qs.parse('foo[base64]=RAWR')).to.eql({ foo: { base64: 'RAWR' }});
expect(qs.parse('foo[64base]=RAWR')).to.eql({ foo: { '64base': 'RAWR' }});
})

it('should support toString() with an array of objects', function(){
expect(qs.parse('foo[0][bar]=baz&foo[1][bat]=boo').foo.toString()).to.eql('[object Object],[object Object]');
})

it('should expand to an array when dupliate keys are present', function(){
expect(qs.parse('items=bar&items=baz&items=raz'))
Expand Down

0 comments on commit 687038a

Please sign in to comment.