diff --git a/ChangeLog b/ChangeLog index 7029ab1..74aeaee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -72,6 +72,10 @@ but would not set (an example does exist), the test would "pass" without 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 ----------------------------- diff --git a/src/pcre2_substitute.c b/src/pcre2_substitute.c index 98952af..ec00ebb 100644 --- a/src/pcre2_substitute.c +++ b/src/pcre2_substitute.c @@ -226,9 +226,9 @@ do 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; } diff --git a/testdata/testinput2 b/testdata/testinput2 index 40a2b4a..e4adf94 100644 --- a/testdata/testinput2 +++ b/testdata/testinput2 @@ -4075,6 +4075,18 @@ a random value. /Ix /(?<=abc)(|def)/g,replace=<$0> 123abcxyzabcdef789abcpqr + +/./replace=$0 + a + +/(.)(.)/replace=$2+$1 + abc + +/(?.)(?.)/replace=$B+$A + abc + +/(.)(.)/g,replace=$2$1 + abcdefgh # End of substitute tests diff --git a/testdata/testoutput2 b/testdata/testoutput2 index 0b4f7ae..e2fa70e 100644 --- a/testdata/testoutput2 +++ b/testdata/testoutput2 @@ -13721,6 +13721,22 @@ Failed: error -34: bad option value /(?<=abc)(|def)/g,replace=<$0> 123abcxyzabcdef789abcpqr 4: 123abc<>xyzabc<>789abc<>pqr + +/./replace=$0 + a + 1: a + +/(.)(.)/replace=$2+$1 + abc + 1: b+ac + +/(?.)(?.)/replace=$B+$A + abc + 1: b+ac + +/(.)(.)/g,replace=$2$1 + abcdefgh + 4: badcfehg # End of substitute tests