Skip to content

Commit 84e17f8

Browse files
committed
Addition of test cases for $regex and fix hanlding stringsAdded two cases for MongoDB $regex usage.Case of $regex without options.Case of $regex with options.Fixed handling of strings in $regex field (missed that part on MongoDB support side).Signed-off-by: Evgeniy Belyi <jeniawhite92@gmail.com>
1 parent c5afe16 commit 84e17f8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,7 @@ function convertOp(path, op, value, parent, arrayPaths) {
121121
// partial newline-sensitive matching
122122
op2 += '(?p)'
123123
}
124-
if (value instanceof RegExp) {
125-
value = value.source
126-
}
127-
return util.pathToText(path, true) + ' ' + op + ' \'' + op2 + util.stringEscape(value) + '\''
124+
return util.pathToText(path, true) + ' ' + op + ' \'' + op2 + util.stringEscape(typeof value === 'string' ? value : value.source) + '\''
128125
case '$eq':
129126
case '$gt':
130127
case '$gte':

test/filter.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ describe('regular expressions', function() {
133133
it('js RegExp using regex', function () {
134134
assert.equal('data->>\'type\' ~ \'(?p)food\'', convert('data', { type: { $regex: /food/ }}))
135135
})
136+
it('js RegExp using regex with options case insensitive', function () {
137+
assert.equal('data->>\'type\' ~* \'(?p)food\'', convert('data', { type: { $regex : /food/, $options: 'i' } }))
138+
})
136139
it('make dot match multiline', function () {
137140
assert.equal('data->>\'type\' ~* \'food\'', convert('data', { type: { $regex : 'food', $options: 'si' } }))
138141
})

0 commit comments

Comments
 (0)