summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorEvan Nixon <evan.nixon@10gen.com>2019-02-12 14:39:17 -0800
committerEvan Nixon <evan.nixon@10gen.com>2019-02-12 15:13:48 -0800
commit613454eb99abe25682f9a50d93ee04e7e90ba314 (patch)
tree8dacb34a5497791cd9936f8d217fd0610917290e /jstests
parent2c65bbe94d04ac0fa62f4fc51a2ece2e748de739 (diff)
downloadmongo-613454eb99abe25682f9a50d93ee04e7e90ba314.tar.gz
SERVER-38621 Do not ignore regex options when specified first
Diffstat (limited to 'jstests')
-rw-r--r--jstests/core/regex.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/jstests/core/regex.js b/jstests/core/regex.js
index e891ddf77fa..1c6a9d6a3bb 100644
--- a/jstests/core/regex.js
+++ b/jstests/core/regex.js
@@ -61,4 +61,23 @@
assert.throws(function() {
t.find({key: {$regex: 'abcd\0xyz'}}).explain();
});
+
+ //
+ // Confirm $options and mode specified in $regex are not allowed to be specified together.
+ //
+ t.drop();
+ assert.commandWorked(t.insert({x: ["abc"]}));
+
+ let regexFirst = assert.throws(() => t.find({x: {$regex: /ab/i, $options: 's'}}).itcount());
+ assert.commandFailedWithCode(regexFirst, 51075);
+
+ let optsFirst = assert.throws(() => t.find({x: {$options: 's', $regex: /ab/i}}).itcount());
+ assert.commandFailedWithCode(optsFirst, 51074);
+
+ t.drop();
+ assert.commandWorked(t.save({x: ["abc"]}));
+
+ assert.eq(1, t.count({x: {$regex: /ABC/i}}));
+ assert.eq(1, t.count({x: {$regex: /ABC/, $options: 'i'}}));
+ assert.eq(1, t.count({x: {$options: 'i', $regex: /ABC/}}));
})();