Skip to content

Commit 687038a

Browse files
__proto__ needed to be restored to objects stored in arrays
1 parent 8ed6a18 commit 687038a

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function compact(obj) {
162162

163163
for (var i in obj) {
164164
if (hasOwnProperty.call(obj, i)) {
165-
ret.push(obj[i]);
165+
ret.push(restoreProto(obj[i]));
166166
}
167167
}
168168

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

184184
function restoreProto(obj) {
185185
if (!Object.create) return obj;
186-
if (isArray(obj)) {
187-
obj.__proto__ = Object.prototype;
188-
return obj;
189-
}
186+
if (isArray(obj)) return obj;
190187
if (obj && 'object' != typeof obj) return obj;
191188

192189
for (var key in obj) {

test/parse.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ describe('qs.parse()', function(){
105105
expect(qs.parse('foo[base64]=RAWR')).to.eql({ foo: { base64: 'RAWR' }});
106106
expect(qs.parse('foo[64base]=RAWR')).to.eql({ foo: { '64base': 'RAWR' }});
107107
})
108+
109+
it('should support toString() with an array of objects', function(){
110+
expect(qs.parse('foo[0][bar]=baz&foo[1][bat]=boo').foo.toString()).to.eql('[object Object],[object Object]');
111+
})
108112

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

0 commit comments

Comments
 (0)