summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>1999-10-14 22:08:22 +0000
committerJarkko Hietaniemi <jhi@iki.fi>1999-10-14 22:08:22 +0000
commit1028017ab8b9674cf749da3584eec9f032360d33 (patch)
tree9d45adc219fe29d5568c6d303fbe82507de3629a
parent73b437c8b23cd73848b265b0c5a0c71d47dc6532 (diff)
downloadperl-1028017ab8b9674cf749da3584eec9f032360d33.tar.gz
Warn inside character classes about unknown backslash escapes
(that are not caught earlier because of being completely unknown, such as \m), such as \z (because they make do sense inside regexen, but not inside character classes). p4raw-id: //depot/cfgperl@4380
-rw-r--r--pod/perldelta.pod9
-rw-r--r--pod/perldiag.pod7
-rw-r--r--regcomp.c20
-rw-r--r--t/pragma/warn/regcomp15
4 files changed, 44 insertions, 7 deletions
diff --git a/pod/perldelta.pod b/pod/perldelta.pod
index b4d4d217de..2ea923724c 100644
--- a/pod/perldelta.pod
+++ b/pod/perldelta.pod
@@ -1395,7 +1395,12 @@ your signed integers. See L<perlfunc/unpack>.
(W) You used a backslash-character combination which is not recognized
by Perl. This combination appears in an interpolated variable or a
-C<'>-delimited regular expression.
+C<'>-delimited regular expression. The character was understood literally.
+
+=item /%s/: Unrecognized escape \\%c in character class passed through
+
+(W) You used a backslash-character combination which is not recognized
+by Perl inside character classes. The character was understood literally.
=item /%s/ should probably be written as "%s"
@@ -1773,7 +1778,7 @@ subvert Perl's population of %ENV for nefarious purposes.
=item Unrecognized escape \\%c passed through
(W) You used a backslash-character combination which is not recognized
-by Perl.
+by Perl. The character was understood literally.
=item Unterminated attribute parameter in attribute list
diff --git a/pod/perldiag.pod b/pod/perldiag.pod
index 11758e0e88..a6a723cc86 100644
--- a/pod/perldiag.pod
+++ b/pod/perldiag.pod
@@ -110,7 +110,12 @@ your signed integers. See L<perlfunc/unpack>.
(W) You used a backslash-character combination which is not recognized
by Perl. This combination appears in an interpolated variable or a
-C<'>-delimited regular expression.
+C<'>-delimited regular expression. The character was understood literally.
+
+=item /%s/: Unrecognized escape \\%c in character class passed through
+
+(W) You used a backslash-character combination which is not recognized
+by Perl inside character classes. The character was understood literally.
=item /%s/ should probably be written as "%s"
diff --git a/regcomp.c b/regcomp.c
index 0dafdd0b9b..2a27b07743 100644
--- a/regcomp.c
+++ b/regcomp.c
@@ -2061,9 +2061,9 @@ tryagain:
default:
if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(*p))
Perl_warner(aTHX_ WARN_UNSAFE,
- "/%.127s/: Unrecognized escape \\%c passed through",
- PL_regprecomp,
- *p);
+ "/%.127s/: Unrecognized escape \\%c passed through",
+ PL_regprecomp,
+ *p);
goto normal_default;
}
break;
@@ -2364,6 +2364,13 @@ S_regclass(pTHX)
value = scan_oct(--PL_regcomp_parse, 3, &numlen);
PL_regcomp_parse += numlen;
break;
+ default:
+ if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(value))
+ Perl_warner(aTHX_ WARN_UNSAFE,
+ "/%.127s/: Unrecognized escape \\%c in character class passed through",
+ PL_regprecomp,
+ value);
+ break;
}
}
if (namedclass > OOB_NAMEDCLASS) {
@@ -2808,6 +2815,13 @@ S_regclassutf8(pTHX)
value = scan_oct(--PL_regcomp_parse, 3, &numlen);
PL_regcomp_parse += numlen;
break;
+ default:
+ if (!SIZE_ONLY && ckWARN(WARN_UNSAFE) && isALPHA(value))
+ Perl_warner(aTHX_ WARN_UNSAFE,
+ "/%.127s/: Unrecognized escape \\%c in character class passed through",
+ PL_regprecomp,
+ value);
+ break;
}
}
if (namedclass > OOB_NAMEDCLASS) {
diff --git a/t/pragma/warn/regcomp b/t/pragma/warn/regcomp
index 88909626db..92b8208a65 100644
--- a/t/pragma/warn/regcomp
+++ b/t/pragma/warn/regcomp
@@ -19,6 +19,10 @@
/%.127s/: false [] range \"%*.*s\" in regexp [S_regclassutf8]
+ /%.127s/: Unrecognized escape \\%c in character class passed through" [S_regclass]
+
+ /%.127s/: Unrecognized escape \\%c in character class passed through" [S_regclassutf8]
+
__END__
# regcomp.c [S_regpiece]
use warnings 'unsafe' ;
@@ -40,8 +44,9 @@ Strange *+?{} on zero-length expression at - line 4.
########
# regcomp.c [S_regatom]
use warnings 'unsafe' ;
-$a =~ /\m/ ;
+$a =~ /a\mb\b/ ;
no warnings 'unsafe' ;
+$a =~ /a\mb\b/ ;
EXPECT
Unrecognized escape \m passed through at - line 3.
########
@@ -139,3 +144,11 @@ EXPECT
/[[:digit:]-b]/: false [] range "[:digit:]-" in regexp at - line 11.
/[[:alpha:]-[:digit:]]/: false [] range "[:alpha:]-" in regexp at - line 12.
/[[:digit:]-[:alpha:]]/: false [] range "[:digit:]-" in regexp at - line 13.
+########
+# regcomp.c [S_regclass S_regclassutf8]
+use warnings 'unsafe' ;
+$a =~ /[a\zb]/ ;
+no warnings 'unsafe' ;
+$a =~ /[a\zb]/ ;
+EXPECT
+/[a\zb]/: Unrecognized escape \z in character class passed through at - line 3.