Fix value equality test to avoid toString
- The where statement can be something like {toString: 'not a function'} - Avoid object string comparison Signed-off-by: Raymond Feng <enjoyjava@gmail.com>
This commit is contained in:
parent
bebfd7d2bd
commit
3d71ea1571
|
@ -613,8 +613,8 @@ function applyFilter(filter) {
|
|||
return value.match(example);
|
||||
}
|
||||
|
||||
if (example === undefined) {
|
||||
return undefined;
|
||||
if (example == null) {
|
||||
return value == null;
|
||||
}
|
||||
|
||||
if (typeof example === 'object' && example !== null) {
|
||||
|
@ -682,9 +682,13 @@ function applyFilter(filter) {
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// compare date
|
||||
if (example instanceof Date && value instanceof Date) {
|
||||
return example.getTime() === value.getTime();
|
||||
}
|
||||
// not strict equality
|
||||
return (example !== null ? example.toString() : example) ==
|
||||
(value != null ? value.toString() : value);
|
||||
return example == value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -339,6 +339,15 @@ describe('Memory connector', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should successfully extract 1 user (Lennon) from the db by date', function(done) {
|
||||
User.find({where: {birthday: new Date('1980-12-08')}},
|
||||
function(err, users) {
|
||||
should(users.length).be.equal(1);
|
||||
should(users[0].name).be.equal('John Lennon');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should successfully extract 2 users from the db', function(done) {
|
||||
User.find({where: {birthday: {between: [new Date(1940, 0), new Date(1990, 0)]}}},
|
||||
function(err, users) {
|
||||
|
@ -565,6 +574,33 @@ describe('Memory connector', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should handle constructor.prototype', function(done) {
|
||||
User.find({where: {'constructor.prototype': {toString: 'Not a function'}}}, function(err,
|
||||
users) {
|
||||
should.not.exist(err);
|
||||
users.length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle constructor/prototype', function(done) {
|
||||
User.find({where: {constructor: {prototype: {toString: 'Not a function'}}}}, function(err,
|
||||
users) {
|
||||
should.not.exist(err);
|
||||
users.length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle toString', function(done) {
|
||||
User.find({where: {toString: 'Not a function'}}, function(err,
|
||||
users) {
|
||||
should.not.exist(err);
|
||||
users.length.should.equal(0);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
function seed(done) {
|
||||
const beatles = [
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue