Fix pcre2test mishandling "end before start" return with POSIX interface.

This commit is contained in:
Philip.Hazel 2017-01-11 17:02:27 +00:00
parent 1226e2e0d0
commit 6332aa1101
4 changed files with 28 additions and 6 deletions

View File

@ -317,6 +317,10 @@ just wastes time. In the UTF case it can also produce redundant entries in
XCLASS lists caused by characters with multiple other cases and pairs of XCLASS lists caused by characters with multiple other cases and pairs of
characters in the same "not-x" sublists. characters in the same "not-x" sublists.
49. A pattern such as /(?=(a\K))/ can report the end of the match being before
its start; pcre2test was not handling this correctly when using the POSIX
interface (it was OK with the native interface).
Version 10.22 29-July-2016 Version 10.22 29-July-2016
-------------------------- --------------------------

View File

@ -6184,18 +6184,27 @@ if ((pat_patctl.control & CTL_POSIX) != 0)
{ {
if (pmatch[i].rm_so >= 0) if (pmatch[i].rm_so >= 0)
{ {
PCRE2_SIZE start = pmatch[i].rm_so;
PCRE2_SIZE end = pmatch[i].rm_eo;
if (start > end)
{
start = pmatch[i].rm_eo;
end = pmatch[i].rm_so;
fprintf(outfile, "Start of matched string is beyond its end - "
"displaying from end to start.\n");
}
fprintf(outfile, "%2d: ", (int)i); fprintf(outfile, "%2d: ", (int)i);
PCHARSV(pp, pmatch[i].rm_so, PCHARSV(pp, start, end - start, utf, outfile);
pmatch[i].rm_eo - pmatch[i].rm_so, utf, outfile);
fprintf(outfile, "\n"); fprintf(outfile, "\n");
if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) || if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) ||
(dat_datctl.control & CTL_ALLAFTERTEXT) != 0) (dat_datctl.control & CTL_ALLAFTERTEXT) != 0)
{ {
fprintf(outfile, "%2d+ ", (int)i); fprintf(outfile, "%2d+ ", (int)i);
PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo, /* Note: don't use the start/end variables here because we want to
utf, outfile); show the text from what is reported as the end. */
fprintf(outfile, "\n"); PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
} fprintf(outfile, "\n"); }
} }
} }
} }

View File

@ -106,4 +106,7 @@
//posix_nosub //posix_nosub
\=offset=70000 \=offset=70000
/(?=(a\K))/
a
# End of testdata/testinput18 # End of testdata/testinput18

View File

@ -162,4 +162,10 @@ Failed: POSIX code 4: ? * + invalid at offset 1000001
** Ignored with POSIX interface: offset ** Ignored with POSIX interface: offset
Matched with REG_NOSUB Matched with REG_NOSUB
/(?=(a\K))/
a
Start of matched string is beyond its end - displaying from end to start.
0: a
1: a
# End of testdata/testinput18 # End of testdata/testinput18