Skip to content

Commit c07a6e8

Browse files
authored
Fix regression in handling of repeated backslash escapes in pcre2_substitute (#857)
1 parent e6783ee commit c07a6e8

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/pcre2_substitute.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ for (; ptr < ptrend; ptr++)
115115
int erc;
116116
int errorcode;
117117
uint32_t ch;
118+
PCRE2_SPTR esc_end_ptr;
118119

119120
if (ptr < ptrend - 1) switch (ptr[1])
120121
{
@@ -137,6 +138,9 @@ for (; ptr < ptrend; ptr++)
137138
goto EXIT;
138139
}
139140

141+
esc_end_ptr = ptr;
142+
ptr -= 1; /* Rewind by one, because the for-loop will increment it */
143+
140144
switch(erc)
141145
{
142146
case 0: /* Data character */
@@ -160,7 +164,8 @@ for (; ptr < ptrend; ptr++)
160164

161165
default:
162166
if (erc < 0)
163-
break; /* capture group reference */
167+
break; /* capture group reference */
168+
ptr = esc_end_ptr;
164169
rc = PCRE2_ERROR_BADREPESCAPE;
165170
goto EXIT;
166171
}

testdata/testinput2

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8314,5 +8314,12 @@ a)"xI
83148314
foo|bar\=offset=1,substitute_subject=F|OOBAR,copy_matched_subject
83158315
foo|bar\=offset=1,substitute_subject=F|OOBAR,copy_matched_subject,zero_terminate
83168316

8317+
# --------------
8318+
# Some more tests for a substitution regression
8319+
# --------------
8320+
8321+
/foo(?<Bar>BAR)?/substitute_extended,replace=X${Bar:+\:\:text}Y
8322+
foo
8323+
fooBAR
83178324

83188325
# End of testinput2

testdata/testoutput2

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23656,6 +23656,15 @@ Failed: error -72: substitute subject differs from prior match call
2365623656
foo|bar\=offset=1,substitute_subject=F|OOBAR,copy_matched_subject,zero_terminate
2365723657
Failed: error -72: substitute subject differs from prior match call
2365823658

23659+
# --------------
23660+
# Some more tests for a substitution regression
23661+
# --------------
23662+
23663+
/foo(?<Bar>BAR)?/substitute_extended,replace=X${Bar:+\:\:text}Y
23664+
foo
23665+
1: XY
23666+
fooBAR
23667+
1: X::textY
2365923668

2366023669
# End of testinput2
2366123670
Error -80: PCRE2_ERROR_BADDATA (unknown error number)

0 commit comments

Comments
 (0)