Fix the comparison for null/boolean values
This commit is contained in:
parent
b5816506e0
commit
bb57fcbe11
|
@ -402,21 +402,25 @@ function applyFilter(filter) {
|
|||
* @private
|
||||
*/
|
||||
function compare(val1, val2) {
|
||||
if(val1 == null || val2 == null) {
|
||||
// Either val1 or val2 is null or undefined
|
||||
return val1 == val2 ? 0 : NaN;
|
||||
}
|
||||
if (typeof val1 === 'number') {
|
||||
return val1 - val2;
|
||||
}
|
||||
if (typeof val1 === 'string') {
|
||||
return (val1 > val2) ? 1 : ((val1 < val2) ? -1 : 0);
|
||||
return (val1 > val2) ? 1 : ((val1 < val2) ? -1 : (val1 == val2) ? 0 : NaN);
|
||||
}
|
||||
if (typeof val1 === 'boolean') {
|
||||
return val1 - val2;
|
||||
}
|
||||
if (val1 instanceof Date) {
|
||||
var result = val1.getTime() - ((val2 && val2.getTime()) || 0);
|
||||
var result = val1 - val2;
|
||||
return result;
|
||||
}
|
||||
// Return NaN if we don't know how to compare
|
||||
return (val1 === val2) ? 0 : NaN;
|
||||
return (val1 == val2) ? 0 : NaN;
|
||||
}
|
||||
|
||||
function testInEquality(example, val) {
|
||||
|
|
|
@ -551,10 +551,14 @@ DataAccessObject._coerce = function (where) {
|
|||
// Coerce the array items
|
||||
if (Array.isArray(val)) {
|
||||
for (var i = 0; i < val.length; i++) {
|
||||
val[i] = DataType(val[i]);
|
||||
if (val[i] !== null && val[i] !== undefined) {
|
||||
val[i] = DataType(val[i]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
val = DataType(val);
|
||||
if (val !== null && val !== undefined) {
|
||||
val = DataType(val);
|
||||
}
|
||||
}
|
||||
// Rebuild {property: {operator: value}}
|
||||
if (operator) {
|
||||
|
|
|
@ -256,6 +256,33 @@ describe('basic-querying', function () {
|
|||
});
|
||||
});
|
||||
|
||||
it('should support number "gt" that is satisfied by null value', function (done) {
|
||||
User.find({order: 'seq', where: { order: { "gt": null }
|
||||
}}, function (err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support number "lt" that is not satisfied by null value', function (done) {
|
||||
User.find({order: 'seq', where: { order: { "lt": null }
|
||||
}}, function (err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support string "gte" that is satisfied by null value', function (done) {
|
||||
User.find({order: 'seq', where: { name: { "gte": null}
|
||||
}}, function (err, users) {
|
||||
should.not.exist(err);
|
||||
users.should.have.property('length', 0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should support string "gte" that is satisfied', function (done) {
|
||||
User.find({order: 'seq', where: { name: { "gte": 'Paul McCartney'}
|
||||
}}, function (err, users) {
|
||||
|
|
Loading…
Reference in New Issue