From 68b93e1074cd8a6759f5898a91b537a76b40eae5 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Thu, 23 Mar 2017 03:29:01 +0300 Subject: [PATCH] Disallow regexp string in arrays for coerce (#1279) Disallow regexp arrays for coerce --- lib/dao.js | 4 +++- test/loopback-dl.test.js | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) 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() {