From eb88f4b7d29b2a89859d52bc679b4939dfe91a08 Mon Sep 17 00:00:00 2001 From: Valjean Clark Date: Thu, 16 Jul 2015 12:17:31 -0700 Subject: [PATCH] merge #308 --- lib/query/index.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/query/index.js b/lib/query/index.js index ad74ac671..a60824ef1 100644 --- a/lib/query/index.js +++ b/lib/query/index.js @@ -217,7 +217,7 @@ Query.prototype.parseExpression = function parseExpression(field, expression) { // Handle `contains` by building up a case insensitive regex if(modifier === 'contains') { val = utils.caseInsensitive(val); - val = '.*' + val + '.*'; + val = '[\\s\\S]*' + val + '[\\s\\S]*'; obj['$regex'] = new RegExp('^' + val + '$', 'i'); return obj; } @@ -225,7 +225,7 @@ Query.prototype.parseExpression = function parseExpression(field, expression) { // Handle `like` if(modifier === 'like') { val = utils.caseInsensitive(val); - val = val.replace(/%/g, '.*'); + val = val.replace(/%/g, '[\\s\\S]*'); obj['$regex'] = new RegExp('^' + val + '$', 'i'); return obj; } @@ -233,7 +233,7 @@ Query.prototype.parseExpression = function parseExpression(field, expression) { // Handle `startsWith` by setting a case-insensitive regex if(modifier === 'startsWith') { val = utils.caseInsensitive(val); - val = val + '.*'; + val = val + '[\\s\\S]*'; obj['$regex'] = new RegExp('^' + val + '$', 'i'); return obj; } @@ -241,7 +241,7 @@ Query.prototype.parseExpression = function parseExpression(field, expression) { // Handle `endsWith` by setting a case-insensitive regex if(modifier === 'endsWith') { val = utils.caseInsensitive(val); - val = '.*' + val; + val = '[\\s\\S]*' + val; obj['$regex'] = new RegExp('^' + val + '$', 'i'); return obj; } @@ -377,10 +377,10 @@ Query.prototype.parseValue = function parseValue(field, modifier, val) { if(!validator.isMongoId(val) && !this.config.caseSensitive) { // Replace Percent Signs, work in a case insensitive fashion by default val = utils.caseInsensitive(val); - val = val.replace(/%/g, '.*'); + val = val.replace(/%/g, '[\\s\\S]*'); val = new RegExp('^' + val + '$', 'i'); } - + return val; }