1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2024-10-26 12:25:09 +03:00

Fix range quantifier on subregex

Make sure to add counted exit transitions before other counter
transitions. Otherwise, we won't backtrack correctly.

Fixes #65.
This commit is contained in:
Nick Wellnhofer 2021-12-20 00:31:41 +01:00
parent 48ed5a74bd
commit 382fb056b5
3 changed files with 7 additions and 3 deletions

2
result/regexp/issue65 Normal file
View File

@ -0,0 +1,2 @@
Regexp: ( (a|bc{0,2})){0,2} d
b d: Ok

2
test/regexp/issue65 Normal file
View File

@ -0,0 +1,2 @@
=>( (a|bc{0,2})){0,2} d
b d

View File

@ -1693,12 +1693,12 @@ xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from,
counter = xmlRegGetCounter(ctxt); counter = xmlRegGetCounter(ctxt);
ctxt->counters[counter].min = atom->min - 1; ctxt->counters[counter].min = atom->min - 1;
ctxt->counters[counter].max = atom->max - 1; ctxt->counters[counter].max = atom->max - 1;
/* count the number of times we see it again */
xmlFAGenerateCountedEpsilonTransition(ctxt, atom->stop,
atom->start, counter);
/* allow a way out based on the count */ /* allow a way out based on the count */
xmlFAGenerateCountedTransition(ctxt, atom->stop, xmlFAGenerateCountedTransition(ctxt, atom->stop,
newstate, counter); newstate, counter);
/* count the number of times we see it again */
xmlFAGenerateCountedEpsilonTransition(ctxt, atom->stop,
atom->start, counter);
/* and if needed allow a direct exit for 0 */ /* and if needed allow a direct exit for 0 */
if (atom->min == 0) if (atom->min == 0)
xmlFAGenerateEpsilonTransition(ctxt, atom->start0, xmlFAGenerateEpsilonTransition(ctxt, atom->start0,