diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mongo/db/matcher/expression_leaf.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/matcher/expression_leaf_test.cpp | 5 |
2 files changed, 4 insertions, 5 deletions
diff --git a/src/mongo/db/matcher/expression_leaf.cpp b/src/mongo/db/matcher/expression_leaf.cpp index b1ca9d30342..fd9d082c518 100644 --- a/src/mongo/db/matcher/expression_leaf.cpp +++ b/src/mongo/db/matcher/expression_leaf.cpp @@ -231,8 +231,8 @@ Status RegexMatchExpression::init(StringData path, StringData regex, StringData // isValidUTF8() checks for UTF-8 which does not map to a series of codepoints but does not // check the validity of the code points themselves. These situations do not cause problems // downstream so we do not do additional work to enforce that the code points are valid. - uassert( - 5108300, "Regular expression is invalid UTF-8", isValidUTF8(_regex) && isValidUTF8(_flags)); + if (!isValidUTF8(_regex) || !isValidUTF8(_flags)) + return Status{ErrorCodes::BadValue, "Regular expression is invalid UTF-8"}; _re.reset(new pcrecpp::RE(_regex.c_str(), flags2options(_flags.c_str()))); diff --git a/src/mongo/db/matcher/expression_leaf_test.cpp b/src/mongo/db/matcher/expression_leaf_test.cpp index af60b5f05d4..253d0795b77 100644 --- a/src/mongo/db/matcher/expression_leaf_test.cpp +++ b/src/mongo/db/matcher/expression_leaf_test.cpp @@ -918,9 +918,8 @@ TEST(RegexMatchExpression, TooLargePattern) { } TEST(RegexMatchExpression, RegexCannotBeInvalidUTF8) { - ASSERT_THROWS_CODE(RegexMatchExpression("path", "^\xff\xff", ""), AssertionException, 5108300); - ASSERT_THROWS_CODE( - RegexMatchExpression("path", "^42", "\xff\xff"), AssertionException, 5108300); + ASSERT_NOT_OK(RegexMatchExpression().init("path", "^\xff\xff", "")); + ASSERT_NOT_OK(RegexMatchExpression().init("path", "^42", "\xff\xff")); } TEST(RegexMatchExpression, MatchesElementSimplePrefix) { |