mirror of
https://gitlab.gnome.org/GNOME/libxml2.git
synced 2025-07-30 22:43:14 +03:00
Fix empty branch in regex
Fixes bug 649244: https://bugzilla.gnome.org/show_bug.cgi?id=649244 Closes #57.
This commit is contained in:
9
result/regexp/bug649244
Normal file
9
result/regexp/bug649244
Normal 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
9
test/regexp/bug649244
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
=>S(a|)E
|
||||||
|
SE
|
||||||
|
SxE
|
||||||
|
=>S(|b)E
|
||||||
|
SE
|
||||||
|
SxE
|
||||||
|
=>S(a||b)E
|
||||||
|
SE
|
||||||
|
SxE
|
14
xmlregexp.c
14
xmlregexp.c
@ -5358,9 +5358,12 @@ xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr to) {
|
|||||||
|
|
||||||
previous = ctxt->state;
|
previous = ctxt->state;
|
||||||
ret = xmlFAParsePiece(ctxt);
|
ret = xmlFAParsePiece(ctxt);
|
||||||
if (ret != 0) {
|
if (ret == 0) {
|
||||||
|
/* Empty branch */
|
||||||
|
xmlFAGenerateEpsilonTransition(ctxt, previous, to);
|
||||||
|
} else {
|
||||||
if (xmlFAGenerateTransitions(ctxt, previous,
|
if (xmlFAGenerateTransitions(ctxt, previous,
|
||||||
(CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0)
|
(CUR=='|' || CUR==')' || CUR==0) ? to : NULL, ctxt->atom) < 0)
|
||||||
return(-1);
|
return(-1);
|
||||||
previous = ctxt->state;
|
previous = ctxt->state;
|
||||||
ctxt->atom = NULL;
|
ctxt->atom = NULL;
|
||||||
@ -5369,7 +5372,8 @@ xmlFAParseBranch(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr to) {
|
|||||||
ret = xmlFAParsePiece(ctxt);
|
ret = xmlFAParsePiece(ctxt);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
if (xmlFAGenerateTransitions(ctxt, previous,
|
if (xmlFAGenerateTransitions(ctxt, previous,
|
||||||
(CUR=='|' || CUR==')') ? to : NULL, ctxt->atom) < 0)
|
(CUR=='|' || CUR==')' || CUR==0) ? to : NULL,
|
||||||
|
ctxt->atom) < 0)
|
||||||
return(-1);
|
return(-1);
|
||||||
previous = ctxt->state;
|
previous = ctxt->state;
|
||||||
ctxt->atom = NULL;
|
ctxt->atom = NULL;
|
||||||
@ -5406,10 +5410,6 @@ xmlFAParseRegExp(xmlRegParserCtxtPtr ctxt, int top) {
|
|||||||
end = ctxt->state;
|
end = ctxt->state;
|
||||||
while ((CUR == '|') && (ctxt->error == 0)) {
|
while ((CUR == '|') && (ctxt->error == 0)) {
|
||||||
NEXT;
|
NEXT;
|
||||||
if (CUR == 0) {
|
|
||||||
ERROR("expecting a branch after |")
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ctxt->state = start;
|
ctxt->state = start;
|
||||||
ctxt->end = NULL;
|
ctxt->end = NULL;
|
||||||
xmlFAParseBranch(ctxt, end);
|
xmlFAParseBranch(ctxt, end);
|
||||||
|
Reference in New Issue
Block a user