Commit c2b0a184 authored by Nick Wellnhofer's avatar Nick Wellnhofer

Fix empty branch in regex

Fixes bug 649244:
https://bugzilla.gnome.org/show_bug.cgi?id=649244

Closes #57.
parent 1fbcf409
Regexp: S(a|)E
SE: Ok
SxE: Fail
Regexp: S(|b)E
SE: Ok
SxE: Fail
Regexp: S(a||b)E
SE: Ok
SxE: Fail
=>S(a|)E
SE
SxE
=>S(|b)E
SE
SxE
=>S(a||b)E
SE
SxE
......@@ -5358,9 +5358,12 @@ xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr to) {
previous = ctxt->state;
ret = xmlFAParsePiece(ctxt);
if (ret != 0) {
if (ret == 0) {
/* Empty branch */
xmlFAGenerateEpsilonTransition(ctxt, previous, to);
} else {
if (xmlFAGenerateTransitions(ctxt, previous,
(CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0)
(CUR=='|' || CUR==')' || CUR==0) ? to : NULL, ctxt->atom) < 0)
return(-1);
previous = ctxt->state;
ctxt->atom = NULL;
......@@ -5369,7 +5372,8 @@ xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr to) {
ret = xmlFAParsePiece(ctxt);
if (ret != 0) {
if (xmlFAGenerateTransitions(ctxt, previous,
(CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0)
(CUR=='|' || CUR==')' || CUR==0) ? to : NULL,
ctxt->atom) < 0)
return(-1);
previous = ctxt->state;
ctxt->atom = NULL;
......@@ -5406,10 +5410,6 @@ xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
end = ctxt->state;
while ((CUR == '|') && (ctxt->error == 0)) {
NEXT;
if (CUR == 0) {
ERROR("expecting a branch after |")
return;
}
ctxt->state = start;
ctxt->end = NULL;
xmlFAParseBranch(ctxt, end);
......
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