[Pcre-svn] [699] code/trunk: Fix *THEN in condition issue.

トップ ページ
このメッセージを削除
著者: Subversion repository
日付:  
To: pcre-svn
題目: [Pcre-svn] [699] code/trunk: Fix *THEN in condition issue.
Revision: 699
          http://vcs.pcre.org/viewvc?view=rev&revision=699
Author:   ph10
Date:     2011-09-20 11:46:54 +0100 (Tue, 20 Sep 2011)


Log Message:
-----------
Fix *THEN in condition issue.

Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/pcre_exec.c
    code/trunk/testdata/testinput2
    code/trunk/testdata/testoutput2


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2011-09-19 15:43:02 UTC (rev 698)
+++ code/trunk/ChangeLog    2011-09-20 10:46:54 UTC (rev 699)
@@ -48,6 +48,9 @@
    computing a minimum subject length in the presence of *ACCEPT is difficult
    (think back references, subroutine calls), and so I have changed the code so
    that no minimum is registered for a pattern that contains *ACCEPT.
+   
+8. If (*THEN) was present in the first (true) branch of a conditional group,
+   it was not handled as intended. 



Version 8.13 16-Aug-2011

Modified: code/trunk/pcre_exec.c
===================================================================
--- code/trunk/pcre_exec.c    2011-09-19 15:43:02 UTC (rev 698)
+++ code/trunk/pcre_exec.c    2011-09-20 10:46:54 UTC (rev 699)
@@ -1275,8 +1275,21 @@
       {
       if (op == OP_SCOND) md->match_function_type = MATCH_CBEGROUP;
       RMATCH(eptr, ecode + 1 + LINK_SIZE, offset_top, md, eptrb, RM49);
-      if (rrc == MATCH_THEN && md->start_match_ptr == ecode)
-        rrc = MATCH_NOMATCH;
+      
+      /* If the result is THEN from within the "true" branch of the condition,
+      md->start_match_ptr will point to the original OP_COND, not to the start 
+      of the branch, so we have do work to see if it matches. If THEN comes 
+      from the "false" branch, md->start_match_ptr does point to OP_ALT. */
+
+      if (rrc == MATCH_THEN)
+        {
+        if (*ecode != OP_ALT)
+          {  
+          do ecode += GET(ecode, 1); while (*ecode == OP_ALT);
+          ecode -= GET(ecode, 1);
+          } 
+        if (md->start_match_ptr == ecode) rrc = MATCH_NOMATCH;   
+        }  
       RRETURN(rrc);
       }
     else                         /* Condition false & no alternative */


Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2    2011-09-19 15:43:02 UTC (rev 698)
+++ code/trunk/testdata/testinput2    2011-09-20 10:46:54 UTC (rev 699)
@@ -3733,6 +3733,21 @@
 /^.*?(?(?=a)a|bc)/
     ba


+/^.*?(?(?=a)a(*THEN)b|c)/
+    ac
+
+/^.*?(?(?=a)a(*THEN)b)c/
+    ac
+
+/^.*?(a(*THEN)b)c/
+    aabc
+
+/^.*?(a(*THEN)b|z)c/
+    aabc
+
+/^.*?(z|a(*THEN)b)c/
+    aabc
+
 /-- --/


/-- These studied versions are here because they are not Perl-compatible; the

Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2    2011-09-19 15:43:02 UTC (rev 698)
+++ code/trunk/testdata/testoutput2    2011-09-20 10:46:54 UTC (rev 699)
@@ -11830,6 +11830,29 @@
     ba
  0: ba


+/^.*?(?(?=a)a(*THEN)b|c)/
+    ac
+ 0: ac
+
+/^.*?(?(?=a)a(*THEN)b)c/
+    ac
+ 0: ac
+
+/^.*?(a(*THEN)b)c/
+    aabc
+ 0: aabc
+ 1: ab
+
+/^.*?(a(*THEN)b|z)c/
+    aabc
+ 0: aabc
+ 1: ab
+
+/^.*?(z|a(*THEN)b)c/
+    aabc
+ 0: aabc
+ 1: ab
+
 /-- --/


/-- These studied versions are here because they are not Perl-compatible; the