Commit a8feeb4c authored by Milo Yip's avatar Milo Yip

Add invalid regex tests and fix a bug

parent c0e7c830
......@@ -463,6 +463,8 @@ private:
switch (codepoint) {
case ']':
if (start == kRegexInvalidRange)
return false; // Error: nothing inside []
if (step == 2) { // Add trailing '-'
SizeType r = NewRange('-');
RAPIDJSON_ASSERT(current != kRegexInvalidRange);
......
......@@ -494,4 +494,40 @@ TEST(Regex, Escape) {
EXPECT_FALSE(re.Match(s)); // Not escaping
}
TEST(Regex, Invalid) {
#define TEST_INVALID(s) \
{\
Regex re(s);\
EXPECT_FALSE(re.IsValid());\
}
TEST_INVALID("a|");
TEST_INVALID("()");
TEST_INVALID(")");
TEST_INVALID("(a))");
TEST_INVALID("(a|)");
TEST_INVALID("(a||b)");
TEST_INVALID("(|b)");
TEST_INVALID("?");
TEST_INVALID("*");
TEST_INVALID("+");
TEST_INVALID("{");
TEST_INVALID("{}");
TEST_INVALID("a{a}");
TEST_INVALID("a{0}");
TEST_INVALID("a{-1}");
TEST_INVALID("a{}");
TEST_INVALID("a{0,}");
TEST_INVALID("a{,0}");
TEST_INVALID("a{1,0}");
TEST_INVALID("a{-1,0}");
TEST_INVALID("a{-1,1}");
TEST_INVALID("[]");
TEST_INVALID("[^]");
TEST_INVALID("[\\a]");
TEST_INVALID("\\a");
#undef TEST_INVALID
}
#undef EURO
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment