Skip to content

Commit

Permalink
cleanup comparisons to undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
nlf committed Aug 7, 2014
1 parent 7328f9a commit 8c8fe36
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
9 changes: 3 additions & 6 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ exports.arrayToObject = function (source) {

var obj = {};
for (var i = 0, il = source.length; i < il; ++i) {
if (source[i] !== undefined &&
source[i] !== null) {
if (typeof source[i] !== 'undefined') {

obj[i] = source[i];
}
Expand Down Expand Up @@ -54,7 +53,7 @@ exports.merge = function (target, source) {

if (Array.isArray(source)) {
for (var i = 0, il = source.length; i < il; ++i) {
if (source[i] !== undefined) {
if (typeof source[i] !== 'undefined') {
if (typeof obj[i] === 'object') {
obj[i] = exports.merge(obj[i], source[i]);
}
Expand Down Expand Up @@ -119,9 +118,7 @@ exports.compact = function (obj) {
compacted[key] = [];

for (var i = 0, l = obj[key].length; i < l; i++) {
if (obj[key].hasOwnProperty(i) &&
obj[key][i] !== null) {

if (typeof obj[key][i] !== 'undefined') {
compacted[key].push(obj[key][i]);
}
}
Expand Down
7 changes: 6 additions & 1 deletion test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,13 @@ describe('#parse', function () {
it('should not throw when a native prototype has an enumerable property', { parallel: false }, function (done) {

Object.prototype.crash = '';
expect(Qs.parse.bind(null, 'test')).to.not.throw();
Array.prototype.crash = '';
expect(Qs.parse.bind(null, 'a=b')).to.not.throw();
expect(Qs.parse('a=b')).to.deep.equal({ a: 'b' });
expect(Qs.parse.bind(null, 'a[][b]=c')).to.not.throw();
expect(Qs.parse('a[][b]=c')).to.deep.equal({ a: [{ b: 'c' }] });
delete Object.prototype.crash;
delete Array.prototype.crash;
done();
});

Expand Down

0 comments on commit 8c8fe36

Please sign in to comment.