Skip to content

Commit eea3e57

Browse files
authored
Merge pull request Tencent#1416 from ylavic/regex_syntax_noassert
GenericRegex: don't throw/abort on syntax error (unclosed parenthesis).
2 parents 30d92a6 + 8c14787 commit eea3e57

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

include/rapidjson/internal/regex.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,8 +395,7 @@ class GenericRegex {
395395
}
396396
return false;
397397

398-
default:
399-
RAPIDJSON_ASSERT(op == kOneOrMore);
398+
case kOneOrMore:
400399
if (operandStack.GetSize() >= sizeof(Frag)) {
401400
Frag e = *operandStack.template Pop<Frag>(1);
402401
SizeType s = NewState(kRegexInvalidState, e.start, 0);
@@ -405,6 +404,10 @@ class GenericRegex {
405404
return true;
406405
}
407406
return false;
407+
408+
default:
409+
// syntax error (e.g. unclosed kLeftParenthesis)
410+
return false;
408411
}
409412
}
410413

test/unittest/regextest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ TEST(Regex, Invalid) {
595595
TEST_INVALID("");
596596
TEST_INVALID("a|");
597597
TEST_INVALID("()");
598+
TEST_INVALID("(");
598599
TEST_INVALID(")");
599600
TEST_INVALID("(a))");
600601
TEST_INVALID("(a|)");

0 commit comments

Comments
 (0)