Skip to content

Commit

Permalink
Fix incorrect positive error code from pcre2_substitute() (#481)
Browse files Browse the repository at this point in the history
  • Loading branch information
NWilson committed Sep 18, 2024
1 parent 2de84f3 commit 829414f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pcre2_substitute.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ for (; ptr < ptrend; ptr++)
ptr -= 1; /* Back to last code unit of escape */
if (errorcode != 0)
{
rc = errorcode;
/* errorcode from check_escape is positive, so must not be returned by
pcre2_substitute(). */
rc = PCRE2_ERROR_BADREPESCAPE;
goto EXIT;
}

Expand Down
6 changes: 6 additions & 0 deletions testdata/testinput2
Original file line number Diff line number Diff line change
Expand Up @@ -4201,6 +4201,12 @@
123abc123\=substitute_overflow_length,replace=[1]x$1z
123abc123\=substitute_overflow_length,replace=[0]x$1z

/a(b)c/substitute_extended
ZabcZ\=replace=>${1:+ yes : no }
ZabcZ\=replace=>${1:+ \o{100} : \o{100} }
ZabcZ\=replace=>${1:+ \o{Z} : no }
ZabcZ\=replace=>${1:+ yes : \o{Z} }

"((?=(?(?=(?(?=(?(?=()))))))))"
a

Expand Down
10 changes: 10 additions & 0 deletions testdata/testoutput2
Original file line number Diff line number Diff line change
Expand Up @@ -13818,6 +13818,16 @@ Failed: error -48: no more memory: 10 code units are needed
123abc123\=substitute_overflow_length,replace=[0]x$1z
Failed: error -48: no more memory: 10 code units are needed

/a(b)c/substitute_extended
ZabcZ\=replace=>${1:+ yes : no }
1: Z> yes Z
ZabcZ\=replace=>${1:+ \o{100} : \o{100} }
1: Z> @ Z
ZabcZ\=replace=>${1:+ \o{Z} : no }
Failed: error -57 at offset 9 in replacement: bad escape sequence in replacement string
ZabcZ\=replace=>${1:+ yes : \o{Z} }
Failed: error -57 at offset 15 in replacement: bad escape sequence in replacement string

"((?=(?(?=(?(?=(?(?=()))))))))"
a
0:
Expand Down

0 comments on commit 829414f

Please sign in to comment.