From f080d010a0bb0efef5a7002e4ccec6afa36434a4 Mon Sep 17 00:00:00 2001 From: Slava Kim Date: Tue, 14 Oct 2014 22:07:14 -0700 Subject: [PATCH] Add tests for #2817 --- packages/minimongo/minimongo_tests.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/minimongo/minimongo_tests.js b/packages/minimongo/minimongo_tests.js index 5b63b2df9e..f1087ff2ee 100644 --- a/packages/minimongo/minimongo_tests.js +++ b/packages/minimongo/minimongo_tests.js @@ -695,6 +695,19 @@ Tinytest.add("minimongo - selector_compiler", function (test) { nomatch({a: /xxx/}, {}); nomatch({a: {$regex: 'xxx'}}, {}); + // GitHub issue #2817: + // Regexps with a global flag ('g') keep a state when tested against the same + // string. Selector shouldn't return different result for similar documents + // because of this state. + var reusedRegexp = /sh/ig; + match({a: reusedRegexp}, {a: 'Shorts'}); + match({a: reusedRegexp}, {a: 'Shorts'}); + match({a: reusedRegexp}, {a: 'Shorts'}); + + match({a: {$regex: reusedRegexp}}, {a: 'Shorts'}); + match({a: {$regex: reusedRegexp}}, {a: 'Shorts'}); + match({a: {$regex: reusedRegexp}}, {a: 'Shorts'}); + test.throws(function () { match({a: {$options: 'i'}}, {a: 12}); });