This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Empty \N{} in regex pattern should force /d to /u
authorKarl Williamson <khw@cpan.org>
Mon, 22 Dec 2014 05:02:30 +0000 (22:02 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 31 Dec 2014 04:18:48 +0000 (21:18 -0700)
\N{} is for Unicode names, even if the name is actually omitted.
(Accepting an empty name is, I believe, an accident, and now is
supported only for backwards compatibility.)

regcomp.c
t/re/re_tests

index e6ddb80..c2521a9 100644 (file)
--- a/regcomp.c
+++ b/regcomp.c
@@ -11174,6 +11174,8 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state, regnode** node_p,
        vFAIL("\\N{NAME} must be resolved by the lexer");
     }
 
+    RExC_uni_semantics = 1; /* Unicode named chars imply Unicode semantics */
+
     if (endbrace == RExC_parse) {   /* empty: \N{} */
        if (node_p) {
            *node_p = reg_node(pRExC_state,NOTHING);
@@ -11185,7 +11187,6 @@ S_grok_bslash_N(pTHX_ RExC_state_t *pRExC_state, regnode** node_p,
         return 0;
     }
 
-    RExC_uni_semantics = 1; /* Unicode named chars imply Unicode semantics */
     RExC_parse += 2;   /* Skip past the 'U+' */
 
     endchar = RExC_parse + strcspn(RExC_parse, ".}");
index 0341f77..dcac974 100644 (file)
@@ -1433,6 +1433,7 @@ foo(\h)bar        foo\tbar        y       $1      \t
 # Verify that \N{U+...} forces Unicode rules
 /\N{U+41}\x{c1}/i      a\x{e1} y       $&      a\x{e1}
 /[\N{U+41}\x{c1}]/i    \x{e1}  y       $&      \x{e1}
+/\N{}\xe4/i    \xc4    y       $&      \xc4            # Empty \N{} should change /d to /u
 
 [\s][\S]       \x{a0}\x{a0}    n       -       -       # Unicode complements should not match same character