summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2015-02-05 13:07:38 -0700
committerKarl Williamson <khw@cpan.org>2015-02-05 13:54:23 -0700
commit7dbd4c448e073ab79489ffeb25479e30e283d84d (patch)
tree0b7822356d38ff4dd2e93c5501e2c956694e8cd2
parentc9a74c77cc7250708801cd921a86741bdcbda6cd (diff)
downloadperl-7dbd4c448e073ab79489ffeb25479e30e283d84d.tar.gz
regcomp.c: Warn on [:^posix:] not being in []
A POSIX character class is has to be in a bracketed character class. A warning is issued when something appearing to be one is found outside. Until this commit the warning wasn't raised for negated classes.
-rw-r--r--pod/perldelta.pod8
-rw-r--r--regcomp.c3
-rw-r--r--t/re/reg_mesg.t1
3 files changed, 12 insertions, 0 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index 674109a7a6..097d28c2a9 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -399,6 +399,14 @@ array, for example, perl would produce a runtime error and not set
C<PL_rs>, but perl code that checked C<$/> would see the array
reference. [perl #123218]
+=item *
+
+In a regular expression pattern, a POSIX class, like C<[:ascii:]>, must
+be inside a bracketed character class, like C</qr[[:ascii:]]>. A
+warning is issued when something looking like a POSIX class is not
+inside a bracketed class. That warning wasn't getting generated when
+the POSIX class was negated: C<[:^ascii:]>. This is now fixed.
+
=back
=head1 Known Problems
diff --git a/regcomp.c b/regcomp.c
index edab543e42..0d6d344970 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -13864,6 +13864,9 @@ S_regclass(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth,
const char *s = RExC_parse;
const char c = *s++;
+ if (*s == '^') {
+ s++;
+ }
while (isWORDCHAR(*s))
s++;
if (*s && c == *s && s[1] == ']') {
diff --git a/t/re/reg_mesg.t b/t/re/reg_mesg.t
index 4abfdf701e..c985c8e1b0 100644
--- a/t/re/reg_mesg.t
+++ b/t/re/reg_mesg.t
@@ -451,6 +451,7 @@ my @death_utf8_only_under_strict = (
my @warning = (
'm/\b*\x{100}/' => '\b* matches null string many times {#} m/\b*{#}\x{100}/',
'm/[:blank:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[:blank:]{#}\x{100}/',
+ 'm/[[:cntrl:]][:^ascii:]\x{100}/' => 'POSIX syntax [: :] belongs inside character classes {#} m/[[:cntrl:]][:^ascii:]{#}\x{100}/',
"m'\\y\\x{100}'" => 'Unrecognized escape \y passed through {#} m/\y{#}\x{100}/',
'/x{3,1}/' => 'Quantifier {n,m} with n > m can\'t match {#} m/x{3,1}{#}/',
'/\08/' => '\'\08\' resolved to \'\o{0}8\' {#} m/\08{#}/',