Merge pull request #691 from strongloop/do-not-coerce-regexp-to-string
Do not coerce RegExp objects to strings
This commit is contained in:
commit
d14721656f
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue