Fix empty branch in regex

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

Closes #57.
This commit is contained in:
Nick Wellnhofer 2019-09-25 13:57:42 +02:00
parent 1fbcf4098b
commit c2b0a184a9
3 changed files with 25 additions and 7 deletions

9
result/regexp/bug649244 Normal file
View File

@ -0,0 +1,9 @@
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

9
test/regexp/bug649244 Normal file
View File

@ -0,0 +1,9 @@
=>S(a|)E
SE
SxE
=>S(|b)E
SE
SxE
=>S(a||b)E
SE
SxE

View File

@ -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);