Merge pull request #691 from strongloop/do-not-coerce-regexp-to-string

Do not coerce RegExp objects to strings
This commit is contained in:
Simon Ho 2015-08-14 09:14:05 -07:00
commit d14721656f
2 changed files with 15 additions and 2 deletions

View File

@ -1196,8 +1196,11 @@ DataAccessObject._coerce = function (where) {
}
} else {
if (val != null) {
if (operator === 'regexp' && val instanceof RegExp) {
// do not coerce regex literals/objects
if (operator === null && val instanceof RegExp) {
// Normalize {name: /A/} to {name: {regexp: /A/}}
operator = 'regexp';
} else if (operator === 'regexp' && val instanceof RegExp) {
// Do not coerce regex literals/objects
} else if (!((operator === 'like' || operator === 'nlike') && val instanceof RegExp)) {
val = DataType(val);
}

View File

@ -356,6 +356,16 @@ describe('Memory connector', function() {
});
});
it('should work when a regex is provided without the regexp operator',
function(done) {
User.find({where: {name: /John.*/i}}, function(err, users) {
should.not.exist(err);
users.length.should.equal(1);
users[0].name.should.equal('John Lennon');
done();
});
});
it('should support the regexp operator with regex strings', function(done) {
User.find({where: {name: {regexp: '^J'}}}, function(err, users) {
should.not.exist(err);