From 382fb056b59c9b54e3d4bf8f2329f3bc5c7d40e0 Mon Sep 17 00:00:00 2001 From: Nick Wellnhofer Date: Mon, 20 Dec 2021 00:31:41 +0100 Subject: [PATCH] Fix range quantifier on subregex Make sure to add counted exit transitions before other counter transitions. Otherwise, we won't backtrack correctly. Fixes #65. --- result/regexp/issue65 | 2 ++ test/regexp/issue65 | 2 ++ xmlregexp.c | 6 +++--- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 result/regexp/issue65 create mode 100644 test/regexp/issue65 diff --git a/result/regexp/issue65 b/result/regexp/issue65 new file mode 100644 index 00000000..46bacd3f --- /dev/null +++ b/result/regexp/issue65 @@ -0,0 +1,2 @@ +Regexp: ( (a|bc{0,2})){0,2} d + b d: Ok diff --git a/test/regexp/issue65 b/test/regexp/issue65 new file mode 100644 index 00000000..b71bc073 --- /dev/null +++ b/test/regexp/issue65 @@ -0,0 +1,2 @@ +=>( (a|bc{0,2})){0,2} d + b d diff --git a/xmlregexp.c b/xmlregexp.c index 984c7ac6..80dfc34a 100644 --- a/xmlregexp.c +++ b/xmlregexp.c @@ -1693,12 +1693,12 @@ xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from, counter = xmlRegGetCounter(ctxt); ctxt->counters[counter].min = atom->min - 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 */ xmlFAGenerateCountedTransition(ctxt, atom->stop, 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 */ if (atom->min == 0) xmlFAGenerateEpsilonTransition(ctxt, atom->start0,