Skip to content

Commit

Permalink
Merge pull request #4161 from DmitryOlshansky/issue-11765
Browse files Browse the repository at this point in the history
Fix issue 7551 - Regex parsing bug for right bracket in character class
  • Loading branch information
Hackerpilot committed Apr 7, 2016
2 parents cf4f09f + afd16ea commit 0ce66bc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
17 changes: 14 additions & 3 deletions std/regex/internal/parser.d
Expand Up @@ -1143,9 +1143,20 @@ struct Parser(R)
opstack.push(Operator.Negate);
enforce(next(), "unexpected end of character class");
}
//[] is prohibited
enforce(current != ']', "wrong character class");
goto default;
else if (current == ']') // []...] is special cased
{
enforce(next(), "wrong character set");
auto pair = parseCharTerm();
pair[0].add(']', ']'+1);
if(pair[1] != Operator.None)
{
if(opstack.top == Operator.Union)
unrollWhile!(unaryFun!"a == a.Union")(vstack, opstack);
opstack.push(pair[1]);
}
vstack.push(pair[0]);
}
break;
case ']':
enforce(unrollWhile!(unaryFun!"a != a.Open")(vstack, opstack),
"character class syntax error");
Expand Down
9 changes: 9 additions & 0 deletions std/regex/internal/tests.d
Expand Up @@ -968,3 +968,12 @@ unittest
assert(matchAll(v, ctPat2).front.hit == v);
}

// bugzilla 7551
unittest
{
auto r = regex("[]abc]*");
assert("]ab".matchFirst(r).hit == "]ab");
assertThrown(regex("[]"));
auto r2 = regex("[]abc--ab]*");
assert("]ac".matchFirst(r2).hit == "]");
}

0 comments on commit 0ce66bc

Please sign in to comment.