Revision: 197
http://www.exim.org/viewvc/pcre2?view=rev&revision=197
Author: ph10
Date: 2015-02-10 12:48:45 +0000 (Tue, 10 Feb 2015)
Log Message:
-----------
Fix replacement bug in pcre2_substitute().
Modified Paths:
--------------
code/trunk/ChangeLog
code/trunk/src/pcre2_substitute.c
code/trunk/testdata/testinput2
code/trunk/testdata/testoutput2
Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog 2015-02-08 17:05:12 UTC (rev 196)
+++ code/trunk/ChangeLog 2015-02-10 12:48:45 UTC (rev 197)
@@ -72,7 +72,11 @@
actually doing anything. Also the fr_CA locale has been added to the list of
locales that can be used.
+14. Fixed a bug in pcre2_substitute(). If a replacement string ended in a
+capturing group number without parentheses, the last character was incorrectly
+literally included at the end of the replacement string.
+
Version 10.00 05-January-2015
-----------------------------
Modified: code/trunk/src/pcre2_substitute.c
===================================================================
--- code/trunk/src/pcre2_substitute.c 2015-02-08 17:05:12 UTC (rev 196)
+++ code/trunk/src/pcre2_substitute.c 2015-02-10 12:48:45 UTC (rev 197)
@@ -226,9 +226,9 @@
if (next >= CHAR_0 && next <= CHAR_9)
{
group = next - CHAR_0;
- while (i < rlength - 1)
+ while (++i < rlength)
{
- next = replacement[++i];
+ next = replacement[i];
if (next < CHAR_0 || next > CHAR_9) break;
group = group * 10 + next - CHAR_0;
}
Modified: code/trunk/testdata/testinput2
===================================================================
--- code/trunk/testdata/testinput2 2015-02-08 17:05:12 UTC (rev 196)
+++ code/trunk/testdata/testinput2 2015-02-10 12:48:45 UTC (rev 197)
@@ -4075,6 +4075,18 @@
/(?<=abc)(|def)/g,replace=<$0>
123abcxyzabcdef789abcpqr
+
+/./replace=$0
+ a
+
+/(.)(.)/replace=$2+$1
+ abc
+
+/(?<A>.)(?<B>.)/replace=$B+$A
+ abc
+
+/(.)(.)/g,replace=$2$1
+ abcdefgh
# End of substitute tests
Modified: code/trunk/testdata/testoutput2
===================================================================
--- code/trunk/testdata/testoutput2 2015-02-08 17:05:12 UTC (rev 196)
+++ code/trunk/testdata/testoutput2 2015-02-10 12:48:45 UTC (rev 197)
@@ -13721,6 +13721,22 @@
/(?<=abc)(|def)/g,replace=<$0>
123abcxyzabcdef789abcpqr
4: 123abc<>xyzabc<><def>789abc<>pqr
+
+/./replace=$0
+ a
+ 1: a
+
+/(.)(.)/replace=$2+$1
+ abc
+ 1: b+ac
+
+/(?<A>.)(?<B>.)/replace=$B+$A
+ abc
+ 1: b+ac
+
+/(.)(.)/g,replace=$2$1
+ abcdefgh
+ 4: badcfehg
# End of substitute tests