Re: [pcre-dev] Bug: No match with studied regex

Góra strony
Delete this message
Autor: Philip Hazel
Data:  
Dla: ND
CC: Pcre-dev
Temat: Re: [pcre-dev] Bug: No match with studied regex
On Thu, 10 Dec 2009, ND wrote:

> pattern: i(?(DEFINE)(?<s>a))
> subject: i
> result: No Match
> expected: i
>
> ...
> and many, many other analogous problems. In fact "DEFINE" construct is not
> work with a studied pattern.
> And user now can not trust in this construct.
> I think this bug is critical. Fix it quickly, please.


The patch below fixes it.

Regards,
Philip

--
Philip Hazel



===================================================================
--- pcre_study.c        (revision 469)
+++ pcre_study.c        (working copy)
@@ -96,13 +96,28 @@


   switch (op)
     {
+    case OP_COND:
+    case OP_SCOND:
+
+    /* If there is only one branch in a condition, the implied branch has zero
+    length, so we don't add anything. This covers the DEFINE "condition"
+    automatically. */
+
+    cs = cc + GET(cc, 1);
+    if (*cs != OP_ALT)
+      {
+      cc = cs + 1 + LINK_SIZE;
+      break;
+      }
+
+    /* Otherwise we can fall through and treat it the same as any other
+    subpattern. */
+
     case OP_CBRA:
     case OP_SCBRA:
     case OP_BRA:
     case OP_SBRA:
     case OP_ONCE:
-    case OP_COND:
-    case OP_SCOND:
     d = find_minlength(cc, startcode, options);
     if (d < 0) return d;
     branchlength += d;