Skip to content

Commit

Permalink
Return "undefined" and "false" instead of throwing "TypeError".
Browse files Browse the repository at this point in the history
  • Loading branch information
albertoleal committed Oct 23, 2014
1 parent 8ace6a4 commit 3e18c47
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ module.exports = function (obj, options) {

var keys = [];

if (!obj) {
return obj;
}

var objKeys = Object.keys(obj);
for (var i = 0, il = objKeys.length; i < il; ++i) {
var key = objKeys[i];
Expand Down
14 changes: 14 additions & 0 deletions test/stringify.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ describe('stringify()', function () {
done();
});

it('returns undefined', function (done) {

var obj = undefined;
expect(Qs.stringify(obj)).to.equal(undefined);
done();
});

it('returns false', function (done) {

var obj = false;
expect(Qs.stringify(obj)).to.equal(false);
done();
});

it('stringifies an object with an empty object as a child', function (done) {

var obj = {
Expand Down

0 comments on commit 3e18c47

Please sign in to comment.