Blob Blame History Raw
From 5a62a5dd8541ee3d21e9035bdce8a16b466f5207 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
Date: Tue, 22 Nov 2011 17:40:57 +0100
Subject: [PATCH] Fix repeated forward reference needed character bug
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

From:
r762 | ph10 | 2011-11-22 14:36:51 +0100 (Út, 22 lis 2011) | 2 lines

16. A repeated forward reference in a pattern such as (a)(?2){2}(.) was
    incorrectly expecting the subject to contain another "a" after the start.

Petr Pisar: Changelog removed.
See <http://lists.pcre.org/lurker/message/20111121.203922.3cfd476e.en.html>.
---
 pcre_compile.c        |    8 ++++++--
 testdata/testinput11  |    3 +++
 testdata/testoutput11 |    6 ++++++
 3 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/pcre_compile.c b/pcre_compile.c
index f1dc714..eaca91d 100644
--- a/pcre_compile.c
+++ b/pcre_compile.c
@@ -4514,7 +4514,8 @@ for (;; ptr++)
             *lengthptr += delta;
             }
 
-          /* This is compiling for real */
+          /* This is compiling for real. If there is a set first byte for
+          the group, and we have not yet set a "required byte", set it. */
 
           else
             {
@@ -5497,7 +5498,9 @@ for (;; ptr++)
 
           /* Insert the recursion/subroutine item, automatically wrapped inside
           "once" brackets. Set up a "previous group" length so that a
-          subsequent quantifier will work. */
+          subsequent quantifier will work. It does not have a set first
+          byte (relevant if it is repeated, because it will then be wrapped 
+          with ONCE brackets). */
 
           *code = OP_ONCE;
           PUT(code, 1, 2 + 2*LINK_SIZE);
@@ -5506,6 +5509,7 @@ for (;; ptr++)
           *code = OP_RECURSE;
           PUT(code, 1, (int)(called - cd->start_code));
           code += 1 + LINK_SIZE;
+          groupsetfirstbyte = FALSE;
 
           *code = OP_KET;
           PUT(code, 1, 2 + 2*LINK_SIZE);
diff --git a/testdata/testinput11 b/testdata/testinput11
index 795e1be..7960f88 100644
--- a/testdata/testinput11
+++ b/testdata/testinput11
@@ -483,4 +483,7 @@ however, we need the complication for Perl. ---/
 /(?&t)(?#()(?(DEFINE)(?<t>a))/
     bac
 
+/(a)(?2){2}(.)/
+    abcd
+
 /-- End of testinput11 --/
diff --git a/testdata/testoutput11 b/testdata/testoutput11
index 6270d5b..ae791e8 100644
--- a/testdata/testoutput11
+++ b/testdata/testoutput11
@@ -942,4 +942,10 @@ No match
     bac
  0: a
 
+/(a)(?2){2}(.)/
+    abcd
+ 0: abcd
+ 1: a
+ 2: d
+
 /-- End of testinput11 --/
-- 
1.7.7.3