Skip to content

Commit

Permalink
merge #308
Browse files Browse the repository at this point in the history
  • Loading branch information
vbud authored and particlebanana committed Jan 25, 2016
1 parent 44ead20 commit eb88f4b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/query/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,31 +217,31 @@ 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;
}

// 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;
}

// 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;
}

// 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;
}
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit eb88f4b

Please # to comment.