Commit ecd8fa34 authored by Milo Yip's avatar Milo Yip

Improve coverage of regex

parent c71825f8
......@@ -375,14 +375,14 @@ private:
bool Eval(Stack<Allocator>& operandStack, Operator op) {
switch (op) {
case kConcatenation:
if (operandStack.GetSize() >= sizeof(Frag) * 2) {
RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag) * 2);
{
Frag e2 = *operandStack.template Pop<Frag>(1);
Frag e1 = *operandStack.template Pop<Frag>(1);
Patch(e1.out, e2.start);
*operandStack.template Push<Frag>() = Frag(e1.start, e2.out, Min(e1.minIndex, e2.minIndex));
return true;
}
return false;
return true;
case kAlternation:
if (operandStack.GetSize() >= sizeof(Frag) * 2) {
......@@ -430,8 +430,7 @@ private:
bool EvalQuantifier(Stack<Allocator>& operandStack, unsigned n, unsigned m) {
RAPIDJSON_ASSERT(n <= m);
if (operandStack.GetSize() < sizeof(Frag))
return false;
RAPIDJSON_ASSERT(operandStack.GetSize() >= sizeof(Frag));
if (n == 0) {
if (m == 0) // a{0} not support
......@@ -647,8 +646,7 @@ private:
// Return whether the added states is a match state
bool AddState(Stack<Allocator>& l, SizeType index) const {
if (index == kRegexInvalidState)
return true;
RAPIDJSON_ASSERT(index != kRegexInvalidState);
const State& s = GetState(index);
if (s.out1 != kRegexInvalidState) { // Split
......
......@@ -17,6 +17,14 @@
using namespace rapidjson::internal;
TEST(Regex, Single) {
Regex re("a");
ASSERT_TRUE(re.IsValid());
EXPECT_TRUE(re.Match("a"));
EXPECT_FALSE(re.Match(""));
EXPECT_FALSE(re.Match("b"));
}
TEST(Regex, Concatenation) {
Regex re("abc");
ASSERT_TRUE(re.IsValid());
......@@ -560,6 +568,9 @@ TEST(Regex, Invalid) {
TEST_INVALID("a{1,0}");
TEST_INVALID("a{-1,0}");
TEST_INVALID("a{-1,1}");
TEST_INVALID("a{4294967296}"); // overflow of unsigned
TEST_INVALID("a{1a}");
TEST_INVALID("[");
TEST_INVALID("[]");
TEST_INVALID("[^]");
TEST_INVALID("[\\a]");
......
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