Merge pull request #1875 from strongloop/3.x-backport-1874

Fix value equality test to avoid toString
This commit is contained in:
Raymond Feng 2020-11-02 10:34:58 -08:00 committed by GitHub
commit d0ac37a727
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 4 deletions

View File

@ -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;
}
/**

View File

@ -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 = [
{