This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
PATCH: [perl #122655] 5.20 regression: '"X" !~ /[x]/i'
authorKarl Williamson <khw@cpan.org>
Sat, 30 Aug 2014 16:44:01 +0000 (10:44 -0600)
committerKarl Williamson <khw@cpan.org>
Mon, 1 Sep 2014 14:48:09 +0000 (08:48 -0600)
This problem occurs only when the pattern is UTF-8, contains a single ASCII
lowercase letter.  It does not match its uppercase counterpart.

regcomp.c
t/re/pat.t

index 2e9f89c..ef6cae9 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -11046,10 +11046,16 @@ S_alloc_maybe_populate_EXACT(pTHX_ RExC_state_t *pRExC_state,
                           EBCDIC, but it works there, as the extra invariants
                           fold to themselves) */
                     *character = toFOLD((U8) code_point);
-                    if (downgradable
-                        && *character == code_point
-                        && ! HAS_NONLATIN1_FOLD_CLOSURE(code_point))
-                    {
+
+                    /* We can downgrade to an EXACT node if this character
+                     * isn't a folding one.  Note that this assumes that
+                     * nothing above Latin1 folds to some other invariant than
+                     * one of these alphabetics; otherwise we would also have
+                     * to check:
+                     *  && (! HAS_NONLATIN1_FOLD_CLOSURE(code_point)
+                     *      || ASCII_FOLD_RESTRICTED))
+                     */
+                    if (downgradable && PL_fold[code_point] == code_point) {
                         OP(node) = EXACT;
                     }
                 }
index ec4eea0..770a45a 100644 (file)
@@ -20,7 +20,7 @@ BEGIN {
     require './test.pl';
 }
 
-plan tests => 737;  # Update this when adding/deleting tests.
+plan tests => 738;  # Update this when adding/deleting tests.
 
 run_tests() unless caller;
 
@@ -1606,6 +1606,12 @@ EOP
         ok('a<b>c' =~ qr<a\<b\>c>, "'\\<' is a literal in qr<...>)");
     }
 
+    {   # Was getting optimized into EXACT (non-folding node)
+        my $x = qr/[x]/i;
+        utf8::upgrade($x);
+        like("X", qr/$x/, "UTF-8 of /[x]/i matches upper case");
+    }
+
 } # End of sub run_tests
 
 1;