Skip to content

Commit

Permalink
cleanup for #26
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Aug 26, 2014
1 parent 0814d70 commit 5dff4e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 12 additions & 8 deletions lib/utils.js
Expand Up @@ -3,9 +3,7 @@

// Declare internals

var internals = {
returnFalse: function () { return false; }
};
var internals = {};


exports.arrayToObject = function (source) {
Expand Down Expand Up @@ -134,12 +132,18 @@ exports.compact = function (obj) {
return compacted;
};


exports.isRegExp = function (obj) {
return Object.prototype.toString.call(obj) === '[object RegExp]';
};

if (typeof Buffer !== 'undefined') {
exports.isBuffer = Buffer.isBuffer;
} else {
exports.isBuffer = internals.returnFalse;
}

exports.isBuffer = function (obj) {

if (typeof Buffer !== 'undefined') {
return Buffer.isBuffer(obj);
}
else {
return false;
}
};
9 changes: 9 additions & 0 deletions test/parse.js
Expand Up @@ -322,4 +322,13 @@ describe('#parse', function () {
expect(result).to.deep.equal(expected);
done();
});

it('does not blow up when Buffer global is missing', function (done) {

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

0 comments on commit 5dff4e3

Please sign in to comment.