Reset the state of regex in minimongo on matching

Fixes #2817. Regular Expressions in JavaScript keep the state when matching for
the same string. When there are two documents with the same value of the
matching field, the minimongo can incorrectly filter collection because regexp
would return different values on different calls.
This commit is contained in:
Slava Kim
2014-10-14 21:53:01 -07:00
parent f83c08e8fa
commit 650ca70fe6

View File

@@ -214,6 +214,11 @@ regexpElementMatcher = function (regexp) {
// Regexps only work against strings.
if (typeof value !== 'string')
return false;
// reset regexp's state to avoid inconsistent matching for objects with the
// same value on consecutive calls of regexp.test
regexp.lastIndex = 0;
return regexp.test(value);
};
};