Skip to content

Commit 1656665

Browse files
committed
Require literal '{' in patterns to be escaped
This has been deprecated since v5.16, with a deprecation message displayed starting in v5.22.
1 parent a27615d commit 1656665

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

pod/perldelta.pod

+11
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ L</Selected Bug Fixes> section.
3232

3333
[ List each security issue as a =head2 entry ]
3434

35+
=head2 Unescaped literal C<"{"> characters in regular expression
36+
patterns are no longer permissible
37+
38+
You have to now say something like C<"\{"> or C<"[{]"> to specify to
39+
match a LEFT CURLY BRACKET. This will allow future extensions to the
40+
language. This restriction is not enforced, nor are there current plans
41+
to enforce it, if the C<"{"> is the first character in the pattern.
42+
43+
These have been deprecated since v5.16, with a deprecation message
44+
displayed starting in v5.22.
45+
3546
=head2 Literal control character variable names are no longer permissible
3647

3748
A variable name may no longer contain a literal control character under

pod/perldiag.pod

+8-5
Original file line numberDiff line numberDiff line change
@@ -6127,18 +6127,21 @@ C<undef *foo>.
61276127
(A) You've accidentally run your script through B<csh> instead of Perl.
61286128
Check the #! line, or manually feed your script into Perl yourself.
61296129

6130-
=item Unescaped left brace in regex is deprecated, passed through in regex;
6130+
=item Unescaped left brace in regex is illegal in regex;
61316131
marked by S<<-- HERE> in m/%s/
61326132

6133-
(D deprecated, regexp) You used a literal C<"{"> character in a regular
6134-
expression pattern. You should change to use C<"\{"> instead, because a
6135-
future version of Perl (tentatively v5.26) will consider this to be a
6136-
syntax error. If the pattern delimiters are also braces, any matching
6133+
(F) You used a literal C<"{"> character in a regular
6134+
expression pattern. You should change to use C<"\{"> or C<[{]> instead.
6135+
If the pattern delimiters are also braces, any matching
61376136
right brace (C<"}">) should also be escaped to avoid confusing the parser,
61386137
for example,
61396138

61406139
qr{abc\{def\}ghi}
61416140

6141+
This restriction is not enforced if the C<"{"> is the first character in
6142+
the pattern; nor is a warning generated for this case, as there are no
6143+
current plans to forbid it.
6144+
61426145
=item unexec of %s into %s failed!
61436146

61446147
(F) The unexec() routine failed for some reason. See your local FSF

regcomp.c

+4-5
Original file line numberDiff line numberDiff line change
@@ -13190,14 +13190,13 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
1319013190
} /* End of switch on '\' */
1319113191
break;
1319213192
case '{':
13193-
/* Currently we don't warn when the lbrace is at the start
13193+
/* Currently we don't care if the lbrace is at the start
1319413194
* of a construct. This catches it in the middle of a
1319513195
* literal string, or when it's the first thing after
1319613196
* something like "\b" */
13197-
if (! SIZE_ONLY
13198-
&& (len || (p > RExC_start && isALPHA_A(*(p -1)))))
13199-
{
13200-
ckWARNregdep(p + 1, "Unescaped left brace in regex is deprecated, passed through");
13197+
if (len || (p > RExC_start && isALPHA_A(*(p -1)))) {
13198+
RExC_parse = p + 1;
13199+
vFAIL("Unescaped left brace in regex is illegal");
1320113200
}
1320213201
/*FALLTHROUGH*/
1320313202
default: /* A literal character */

t/re/pat_advanced.t

-5
Original file line numberDiff line numberDiff line change
@@ -1159,11 +1159,6 @@ sub run_tests {
11591159
}
11601160

11611161
{
1162-
# \, breaks {3,4}
1163-
no warnings qw{deprecated regexp};
1164-
ok "xaaay" !~ /xa{3\,4}y/, '\, in a pattern';
1165-
ok "xa{3,4}y" =~ /xa{3\,4}y/, '\, in a pattern';
1166-
11671162
# \c\ followed by _
11681163
ok "x\c_y" !~ /x\c\_y/, '\_ in a pattern';
11691164
ok "x\c\_y" =~ /x\c\_y/, '\_ in a pattern';

t/re/reg_mesg.t

+4-6
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,10 @@ my @death =
268268
'/(?[\ |!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ |!{#}])/', # [perl #126180]
269269
'/(?[()-!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[()-!{#}])/', # [perl #126204]
270270
'/(?[!()])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[!(){#}])/', # [perl #126404]
271+
'/\w{/' => 'Unescaped left brace in regex is illegal {#} m/\w{{#}/',
272+
'/\q{/' => 'Unescaped left brace in regex is illegal {#} m/\q{{#}/',
273+
'/:{4,a}/' => 'Unescaped left brace in regex is illegal {#} m/:{{#}4,a}/',
274+
'/xa{3\,4}y/' => 'Unescaped left brace in regex is illegal {#} m/xa{{#}3\,4}y/',
271275
'/abc/xix' => 'Only one /x regex modifier is allowed',
272276
'/(?xmsixp:abc)/' => 'Only one /x regex modifier is allowed {#} m/(?xmsixp{#}:abc)/',
273277
'/(?xmsixp)abc/' => 'Only one /x regex modifier is allowed {#} m/(?xmsixp{#})abc/',
@@ -617,12 +621,6 @@ my @experimental_regex_sets = (
617621
);
618622

619623
my @deprecated = (
620-
'/\w{/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/\w{{#}/',
621-
'/\q{/' => [
622-
'Unrecognized escape \q{ passed through {#} m/\q{{#}/',
623-
'Unescaped left brace in regex is deprecated, passed through {#} m/\q{{#}/'
624-
],
625-
'/:{4,a}/' => 'Unescaped left brace in regex is deprecated, passed through {#} m/:{{#}4,a}/',
626624
);
627625

628626
for my $strict ("", "use re 'strict';") {

0 commit comments

Comments
 (0)