Skip to content

Commit bf50eee

Browse files
authored
Add matching error-offset output to pcre2test for substitute (#757)
1 parent ae1593f commit bf50eee

File tree

6 files changed

+112
-7
lines changed

6 files changed

+112
-7
lines changed

src/pcre2_substitute.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ for (; ptr < ptrend; ptr++)
129129
ptr += 1; /* Must point after \ */
130130
erc = PRIV(check_escape)(&ptr, ptrend, &ch, &errorcode,
131131
code->overall_options, code->extra_options, code->top_bracket, FALSE, NULL);
132-
ptr -= 1; /* Back to last code unit of escape */
133132
if (errorcode != 0)
134133
{
135134
/* errorcode from check_escape is positive, so must not be returned by

src/pcre2test.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8987,6 +8987,25 @@ if (dat_datctl.replacement[0] != 0)
89878987
if (rc == PCRE2_ERROR_NOMEMORY &&
89888988
(xoptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0)
89898989
fprintf(outfile, ": %ld code units are needed", (long int)nsize);
8990+
8991+
if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET)
8992+
{
8993+
PCRE2_SIZE full_rlen = (rlen != PCRE2_ZERO_TERMINATED)? rlen :
8994+
STRLEN(rbptr);
8995+
8996+
fprintf(outfile, "\n here: ");
8997+
if (nsize > 0)
8998+
{
8999+
PTRUNCV(rbptr, full_rlen, nsize, TRUE, utf, outfile);
9000+
fprintf(outfile, " ");
9001+
}
9002+
fprintf(outfile, "|<--|");
9003+
if (nsize < full_rlen)
9004+
{
9005+
fprintf(outfile, " ");
9006+
PTRUNCV(rbptr, full_rlen, nsize, FALSE, utf, outfile);
9007+
}
9008+
}
89909009
}
89919010
else
89929011
{

testdata/testoutput10

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,7 @@ Failed: error 151 at offset 4: octal value is greater than \377 in 8-bit non-UTF
20002000
/abc/substitute_extended
20012001
abc\=replace=\400
20022002
Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string
2003+
here: \400 |<--|
20032004

20042005
/\400/python_octal
20052006
Failed: error 202 at offset 4: octal value given by \ddd is greater than \377 (forbidden by PCRE2_EXTRA_PYTHON_OCTAL)
@@ -2008,6 +2009,7 @@ Failed: error 202 at offset 4: octal value given by \ddd is greater than \377 (f
20082009
/abc/substitute_extended,python_octal
20092010
abc\=replace=\400
20102011
Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string
2012+
here: \400 |<--|
20112013

20122014
/\400/utf
20132015

@@ -2022,6 +2024,7 @@ Failed: error 202 at offset 4: octal value given by \ddd is greater than \377 (f
20222024
/abc/utf,substitute_extended,python_octal
20232025
abc\=replace=\400
20242026
Failed: error -57 at offset 4 in replacement: bad escape sequence in replacement string
2027+
here: \400 |<--|
20252028

20262029
/[\x00-\x2f\x11-\xff]+/B
20272030
------------------------------------------------------------------

0 commit comments

Comments
 (0)