PATCH: [perl #114982]: case-insensitive regex bug with UTF8-flagged strings
authorKarl Williamson <public@khwilliamson.com>
Thu, 4 Oct 2012 04:17:19 +0000 (22:17 -0600)
committerKarl Williamson <public@khwilliamson.com>
Tue, 9 Oct 2012 17:16:06 +0000 (11:16 -0600)
commitc74f6de970ef0f0eb8ba43b1840fde0cf5a45497
tree471d899cdf6ce4252457e0f81b4366b455fdaa73
parentfb241e71f66a109447972250b3da4dcbffea0e71
PATCH: [perl #114982]: case-insensitive regex bug with UTF8-flagged strings

It turns out that this whole area in regexec.c has never worked
properly, we just didn't have test coverage for it.  Indeed, the portion
that deals with CURLYM had never been updated to include UTF-8!
The failure rate for the new tests added by this commit on the blead
that existed just prior to this commit was 96%.  (4% pass)

This commit refactors the part of regexec.c that deals with quantifiers
and case insensitive matching, and adds comprehensive tests.

Consider a regex of the form A*B.  How do we know how many of A* to
match?  The answer is we don't, until we try B.  But if B begins with
text, we can easily rule out places where the next thing isn't a B.
Only if the next character (following where we are) is the first
character of B, is this a potential match; otherwise it isn't, so there
is no need to even try B.

Code existed to do this, but it was wrong in many ways.  If B can match
case-insensitively under /i, then there may be two or more possible
characters that could begin B.  The previous code assumed there was a
max of two.  It didn't adequately account for the differences between
/a, /d, /l, and /u; and as I mentioned above, in one place it didn't
know that there was such a thing as UTF-8.  Also, it assumed that all
code points can fit into an I32.

To do this right takes quite a bit more intelligence then was there;
and it needs to be done in two different places.  So, this commit
extracts out the code into a single subroutine, heavily modified to
account for the various oversights that were there previously.

The pre-existing infrastructure of fold_grind.t allowed the tests to be
added easily.  I did not add tests for the above-I32 problems, as it
turns out that there are other bugs on these, [perl #115166]
regexec.c
t/re/fold_grind.t