Skip to content

Commit

Permalink
Don't overwrite null values
Browse files Browse the repository at this point in the history
  • Loading branch information
geek committed Aug 14, 2014
1 parent 8e8baa5 commit 3cd85c4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 0 additions & 2 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,5 +153,3 @@ module.exports = function (str, depth, delimiter) {

return Utils.compact(obj);
};


2 changes: 1 addition & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ exports.decode = function (str) {

exports.compact = function (obj) {

if (typeof obj !== 'object') {
if (typeof obj !== 'object' || obj === null) {
return obj;
}

Expand Down
24 changes: 22 additions & 2 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('#parse', function () {
done();
});

it('should compact sparse arrays', function (done) {
it('compacts sparse arrays', function (done) {

expect(Qs.parse('a[10]=1&a[2]=2')).to.deep.equal({ a: ['2', '1'] });
done();
Expand Down Expand Up @@ -253,9 +253,29 @@ describe('#parse', function () {
done();
});

it('should not use non-string objects as delimiters', function (done) {
it('does not use non-string objects as delimiters', function (done) {

expect(Qs.parse('a=b&c=d', {})).to.deep.equal({ a: 'b', c: 'd' });
done();
});

it('parses an object', function (done) {

var input = {
"user[name]": {"pop[bob]": 3},
"user[email]": null
};

var expected = {
"user": {
"name": {"pop[bob]": 3},
"email": null
}
};

var result = Qs.parse(input);

expect(result).to.deep.equal(expected);
done();
});
});

0 comments on commit 3cd85c4

Please sign in to comment.