diff --git a/lib/dao.js b/lib/dao.js index 1bdce64a..e954e32f 100644 --- a/lib/dao.js +++ b/lib/dao.js @@ -1737,7 +1737,9 @@ DataAccessObject._coerce = function(where, options) { if (Array.isArray(val)) { for (var i = 0; i < val.length; i++) { if (val[i] !== null && val[i] !== undefined) { - val[i] = DataType(val[i]); + if (!(val[i] instanceof RegExp)) { + val[i] = DataType(val[i]); + } } } } else { diff --git a/test/loopback-dl.test.js b/test/loopback-dl.test.js index a03ca33f..dbd166dd 100644 --- a/test/loopback-dl.test.js +++ b/test/loopback-dl.test.js @@ -1308,6 +1308,7 @@ describe('DataAccessObject', function() { model = ds.createModel('M1', { id: {type: String, id: true}, age: Number, + string: 'string', vip: Boolean, date: Date, location: 'GeoPoint', @@ -1653,6 +1654,12 @@ describe('DataAccessObject', function() { assert.deepEqual(where, {age: {inq: ['xyz', 12]}}); }); + it('does not coerce to a string for a regexp value in an array ', + function() { + where = model._coerce({string: {inq: [/xyz/i, new RegExp(/xyz/i)]}}); + assert.deepEqual(where, {string: {inq: [/xyz/i, /xyz/i]}}); + }); + // settings it('gets settings in priority', function() {