From 2c4d3942e4dd0dbbfccc43b9cb28d8258afaaca4 Mon Sep 17 00:00:00 2001 From: "Philip.Hazel" Date: Thu, 18 Feb 2021 09:46:08 +0000 Subject: [PATCH] Fix \K within recursion bug in interpreter. --- ChangeLog | 4 ++++ src/pcre2_match.c | 4 +++- testdata/testinput1 | 3 +++ testdata/testoutput1 | 4 ++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index bcf9db8..0891adf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -35,6 +35,10 @@ now runs clean and the resulting "configure" seems to work, so I hope nothing is broken. Later: the requirement for autoconf 2.70 broke some automatic test robots. It doesn't seem to be necessary: trying a reduction to 2.60. +6. The pattern /a\K.(?0)*/ when matched against "abac" by the interpreter gave +the answer "bac", whereas Perl and JIT both yield "c". This was because the +effect of \K was not propagating back from the recursion. This is now fixed. + Version 10.36 04-December-2020 ------------------------------ diff --git a/src/pcre2_match.c b/src/pcre2_match.c index e3f78c2..7d9cad0 100644 --- a/src/pcre2_match.c +++ b/src/pcre2_match.c @@ -818,10 +818,12 @@ fprintf(stderr, "++ op=%d\n", *Fecode); /* N is now the frame of the recursion; the previous frame is at the OP_RECURSE position. Go back there, copying the current subject position - and mark, and move on past the OP_RECURSE. */ + and mark, and the start_match position (\K might have changed it), and + then move on past the OP_RECURSE. */ P->eptr = Feptr; P->mark = Fmark; + P->start_match = Fstart_match; F = P; Fecode += 1 + LINK_SIZE; continue; diff --git a/testdata/testinput1 b/testdata/testinput1 index bb4ddb7..4cf1126 100644 --- a/testdata/testinput1 +++ b/testdata/testinput1 @@ -6429,4 +6429,7 @@ ef) x/x,mark /a{65536/ >a{65536< +/a\K.(?0)*/ + abac + # End of testinput1 diff --git a/testdata/testoutput1 b/testdata/testoutput1 index 05b310b..8d4c108 100644 --- a/testdata/testoutput1 +++ b/testdata/testoutput1 @@ -10188,4 +10188,8 @@ No match >a{65536< 0: a{65536 +/a\K.(?0)*/ + abac + 0: c + # End of testinput1