mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Correct mongo selector rewrite for {$regex: /foo/, $options: '...'}
This commit is contained in:
@@ -266,6 +266,10 @@ Meteor.Collection._rewriteSelector = function (selector) {
|
||||
ret[key] = convertRegexpToMongoSelector(value);
|
||||
} else if (value && value.$regex instanceof RegExp) {
|
||||
ret[key] = convertRegexpToMongoSelector(value.$regex);
|
||||
// if value is {$regex: /foo/, $options: ...} then $options
|
||||
// override the ones set on $regex.
|
||||
if (value.$options)
|
||||
ret[key].$options = value.$options;
|
||||
}
|
||||
else if (_.contains(['$or','$and','$nor'], key)) {
|
||||
// Translate lower levels of $and/$or/$nor
|
||||
|
||||
@@ -909,7 +909,9 @@ Tinytest.add('mongo-livedata - rewrite selector', function (test) {
|
||||
{x: /^a/i},
|
||||
{y: /^b/},
|
||||
{z: {$regex: /^c/i}},
|
||||
{w: {$regex: '^[abc]', $options: 'i'}} // make sure we don't break vanilla selectors
|
||||
{w: {$regex: '^[abc]', $options: 'i'}}, // make sure we don't break vanilla selectors
|
||||
{v: {$regex: /O/, $options: 'i'}}, // $options should override the ones on the RegExp object
|
||||
{u: {$regex: /O/m, $options: 'i'}} // $options should override the ones on the RegExp object
|
||||
]},
|
||||
{'$nor': [
|
||||
{s: /^d/},
|
||||
@@ -923,7 +925,9 @@ Tinytest.add('mongo-livedata - rewrite selector', function (test) {
|
||||
{x: {$regex: '^a', $options: 'i'}},
|
||||
{y: {$regex: '^b'}},
|
||||
{z: {$regex: '^c', $options: 'i'}},
|
||||
{w: {$regex: '^[abc]', $options: 'i'}}
|
||||
{w: {$regex: '^[abc]', $options: 'i'}},
|
||||
{v: {$regex: 'O', $options: 'i'}},
|
||||
{u: {$regex: 'O', $options: 'i'}}
|
||||
]},
|
||||
{'$nor': [
|
||||
{s: {$regex: '^d'}},
|
||||
|
||||
Reference in New Issue
Block a user