This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl 127537] /\W/ regression with UTF-8
authorKarl Williamson <khw@cpan.org>
Sat, 13 Feb 2016 22:35:11 +0000 (15:35 -0700)
committerKarl Williamson <khw@cpan.org>
Fri, 19 Feb 2016 03:44:02 +0000 (20:44 -0700)
This bug is apparently uncommon in the field, as I was the one who
discovered it.  It requires a UTF-8 pattern containing a complemented
posix class, like \W or \S, in an inverted character class, like
[^\Wfoo] in a pattern that also has a synthetic start class generated by
the regex optimizer for it .

The fix is trivial.

pod/perldelta.pod
regcomp.c
t/re/re_tests

index 55db093..9c64130 100644 (file)
@@ -577,6 +577,14 @@ specification is very close to one of the 14 legal POSIX classes.  (See
 L<perlrecharclass/POSIX Character Classes>.)
 [perl #8904]
 
+=item *
+
+Certain regex patterns involving a complemented posix class in an
+inverted bracketed character class, and matching something else
+optionally would improperly fail to match.  An example of one that could
+fail is C</qr/_?[^\Wbar]\x{100}/>.  This has been fixed.
+[perl #127537]
+
 =back
 
 =head1 Known Problems
index 5dbccfb..645c612 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -1420,8 +1420,10 @@ S_get_ANYOF_cp_list_for_ssc(pTHX_ const RExC_state_t *pRExC_state,
     }
 
     /* If this can match all upper Latin1 code points, have to add them
-     * as well */
-    if (OP(node) == ANYOFD
+     * as well.  But don't add them if inverting, as when that gets done below,
+     * it would exclude all these characters, including the ones it shouldn't
+     * that were added just above */
+    if (! (ANYOF_FLAGS(node) & ANYOF_INVERT) && OP(node) == ANYOFD
         && (ANYOF_FLAGS(node) & ANYOF_SHARED_d_MATCHES_ALL_NON_UTF8_NON_ASCII_non_d_WARN_SUPER))
     {
         _invlist_union(invlist, PL_UpperLatin1, &invlist);
index b226123..d32b031 100644 (file)
@@ -1615,6 +1615,8 @@ a(.)\4294967298   ab\o{42}94967298        ya      $1      b       \d not converted to native; \o{} is
 ^m?(\d)(.*)\1$ 5b5     y       $1      5
 ^m?(\d)(.*)\1$ aba     n       -       -
 
+^_?[^\W_0-9]\w\z       \xAA\x{100}     y       $&      \xAA\x{100}             [perl #127537]
+
 # 17F is 'Long s';  This makes sure the a's in /aa can be separate
 /s/ai  \x{17F} y       $&      \x{17F}
 /s/aia \x{17F} n       -       -