diff options
author | Arun Banala <arun.banala@mongodb.com> | 2019-03-28 14:36:10 +0000 |
---|---|---|
committer | Arun Banala <arun.banala@mongodb.com> | 2019-04-01 15:44:19 +0100 |
commit | 1d8ddd2d2d480bc0b840b506c3630c82be8c09a2 (patch) | |
tree | 0261c9dffbe39bd7bfb0348e8b029b0b5446f8bd /jstests/aggregation | |
parent | b6761b00896e78c1e30e565ee82752bcc7d252f0 (diff) | |
download | mongo-1d8ddd2d2d480bc0b840b506c3630c82be8c09a2.tar.gz |
SERVER-40343 Better handling of errors from PCRE in $regex expressions
Diffstat (limited to 'jstests/aggregation')
-rw-r--r-- | jstests/aggregation/expressions/regex.js | 6 | ||||
-rw-r--r-- | jstests/aggregation/expressions/regex_limits.js | 14 |
2 files changed, 11 insertions, 9 deletions
diff --git a/jstests/aggregation/expressions/regex.js b/jstests/aggregation/expressions/regex.js index fed44601ae7..618528ffa38 100644 --- a/jstests/aggregation/expressions/regex.js +++ b/jstests/aggregation/expressions/regex.js @@ -254,7 +254,7 @@ assert.commandWorked(coll.insert({_id: 3, text: "ab\ncd"})); // LIMIT_MATCH option to limit the number of comparisons PCRE does internally. - testRegexFindAggForKey(2, {input: "$text", regex: "(*LIMIT_MATCH=1)fé"}, []); + testRegexAggException({input: "$text", regex: "(*LIMIT_MATCH=1)fé"}, 51156); testRegexFindAggForKey(2, {input: "$text", regex: "(*LIMIT_MATCH=3)(fé)"}, [{"match": "fé", "idx": 2, "captures": ["fé"]}]); @@ -270,8 +270,8 @@ testRegexFindAggForKey(2, {input: "$text", regex: String.raw `(*LIMIT_MATCH=5)(*UCP)^(\w+)`}, [{"match": "cafétéria", "idx": 0, "captures": ["cafétéria"]}]); - testRegexFindAggForKey( - 2, {input: "$text", regex: String.raw `(*LIMIT_MATCH=1)(*UCP)^(\w+)`}, []); + testRegexAggException({input: "$text", regex: String.raw `(*LIMIT_MATCH=1)(*UCP)^(\w+)`}, + 51156); })(); (function testWithUnicodeData() { diff --git a/jstests/aggregation/expressions/regex_limits.js b/jstests/aggregation/expressions/regex_limits.js index bcf3679b001..8ae924f65eb 100644 --- a/jstests/aggregation/expressions/regex_limits.js +++ b/jstests/aggregation/expressions/regex_limits.js @@ -89,12 +89,14 @@ "captures": expectedOutputCaptures }]); - // Weird case, stops matching after certain limit but doesn't error. - const bufferNoMatch = 2553; - pattern = "(d)".repeat(bufferNoMatch) + pattern; - testRegexAgg({input: "$z", regex: pattern}, []); - - // Add more data and verify that PCRE throws an error. + // In this case, during execution, PCRE will hit the PCRE_ERROR_RECURSIONLIMIT because of + // high number of captures and return an error. + const bufferExecutionFailure = 2553; + pattern = "(d)".repeat(bufferExecutionFailure) + pattern; + testRegexAggException({input: "$z", regex: pattern}, 51156); + + // Add one more capture group to the pattern so that it tips over the maximum regex length + // limit, and verify that PCRE throws an error while attempting to compile. pattern = "(d)" + pattern; testRegexAggException({input: "$z", regex: pattern}, 51111); })(); |