Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 17e2b8d

Browse files
committed
Less m/{}/ Unescaped left brace in regex is deprecated here warnings
Only check for Name: \N{} Property: \p{}, \P{} Break: \b{}, \B{} Code: \x{}, \o{} Group: \g{} and allow other chars before a { automake and more widespread utils does not need to be plagued by spurious "Unescaped left brace in regex" warnings, when they dont need to be quoted. Undeprecate those new errors, there's nothing more to reserve (yet). strpbrk is C89. Fixes [cperl #362]
1 parent 5cc2d12 commit 17e2b8d

File tree

5 files changed

+75
-18
lines changed

5 files changed

+75
-18
lines changed

.git-rr-cache

Submodule .git-rr-cache updated 72 files

pod/perlcdelta.pod

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,25 @@ See L<[cperl #117]|https://github.com/perl11/cperl/issues/117>, cperl-only.
7777

7878
=head1 Deprecations
7979

80-
XXX Any deprecated features, syntax, modules etc. should be listed here.
80+
=head2 Undeprecate "Unescaped left brace in regex" warnings and errors
81+
82+
In cperl only the following special unicode groups within regexes are reserved:
83+
84+
Name: \N{
85+
Property: \p{ \P{
86+
Break: \b{ \B{
87+
Code: \x{ \o{
88+
Group: \g{
89+
90+
All other C</{}/> sequences are allowed in cperl and not deprecated
91+
anymore. There's no need to quote the literal C<\{> and C<\}>, only if
92+
it's ambiguous and can be mixed up with those reserved unicode groups.
93+
94+
B<automake> and more widespread utils does not need to be plagued by
95+
spurious "Unescaped left brace in regex" warnings, when they dont need
96+
to be quoted. We undeprecated those new warnings and errors, there's
97+
nothing more to reserve (yet).
98+
L<[cperl #362]|https://github.com/perl11/cperl/issues/362>
8199

82100
=head2 Module removals
83101

pod/perldiag.pod

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6841,7 +6841,9 @@ still just deprecated. This is because of an oversight: some uses of a
68416841
literal C<{> that should have raised a deprecation warning starting in
68426842
v5.20 did not warn until v5.26. By making the already-warned uses fatal
68436843
now, some of the planned extensions can be made to the language sooner.
6844-
The cases which are still allowed will be fatal in Perl 5.30 or 5.32.
6844+
The cases which are still allowed will be fatal in Perl 5.30 or 5.32,
6845+
but cperl allows more. In cperl only the combinations with C<\NpPbBxog{}>
6846+
are illegal.
68456847

68466848
The contexts where no warnings or errors are raised are:
68476849

@@ -6869,6 +6871,16 @@ as the first character following a quantifier
68696871

68706872
/\s*{/
68716873

6874+
=item *
6875+
6876+
in cperl only if the unicode group is one of the following reserved:
6877+
6878+
Name: /\N{/
6879+
Property: /\p{/ /\P{/
6880+
Break: /\b{/ /\B{/
6881+
Code: /\x{/ /\o{/
6882+
Group: /\g{/
6883+
68726884
=back
68736885

68746886
=for comment
@@ -6928,6 +6940,16 @@ as the first character following a quantifier
69286940

69296941
/\s*{/
69306942

6943+
=item *
6944+
6945+
in cperl only if the unicode group is one of the following reserved:
6946+
6947+
Name: /\N{/
6948+
Property: /\p{/ /\P{/
6949+
Break: /\b{/ /\B{/
6950+
Code: /\x{/ /\o{/
6951+
Group: /\g{/
6952+
69316953
=back
69326954

69336955
=item Unescaped literal '%c' in regex; marked by <-- HERE in m/%s/

regcomp.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11634,7 +11634,8 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth)
1163411634
} /* end switch */
1163511635
}
1163611636
else {
11637-
if (*RExC_parse == '{' && PASS2) {
11637+
/* [cperl #362] */
11638+
if (*RExC_parse == '{' && PASS2 && strpbrk(RExC_parse-1, "NpPbBxog") == RExC_parse-1) {
1163811639
ckWARNregdep(RExC_parse + 1,
1163911640
"Unescaped left brace in regex is "
1164011641
"deprecated here (and will be fatal "
@@ -13278,7 +13279,9 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
1327813279

1327913280
finish_meta_pat:
1328013281
if ( UCHARAT(RExC_parse + 1) == '{'
13281-
&& UNLIKELY(! new_regcurly(RExC_parse + 1, RExC_end)))
13282+
&& UNLIKELY(! new_regcurly(RExC_parse + 1, RExC_end))
13283+
&& strpbrk(RExC_parse-1, "NpPbBxog") == RExC_parse-1 /* [cperl #362] */
13284+
)
1328213285
{
1328313286
RExC_parse += 2;
1328413287
vFAIL("Unescaped left brace in regex is illegal here");
@@ -13854,10 +13857,11 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
1385413857
break;
1385513858
case '{':
1385613859
/* Currently we allow an lbrace at the start of a construct
13857-
* without raising a warning. This is because we think we
13858-
* will never want such a brace to be meant to be other
13859-
* than taken literally. */
13860-
if (len || (p > RExC_start && isALPHA_A(*(p - 1)))) {
13860+
* without raising a warning.
13861+
* cperl allows all chars besides \NpPbBxog{} [cperl #362]
13862+
* This is because we think we will never want such a brace to be
13863+
* meant to be other than taken literally. */
13864+
if (len || (p > RExC_start && strpbrk(p-1, "NpPbBxog") == p-1)) {
1386113865

1386213866
/* But, we raise a fatal warning otherwise, as the
1386313867
* deprecation cycle has come and gone. Except that it
@@ -13869,7 +13873,7 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
1386913873
* quantifier specification */
1387013874
if ( RExC_strict
1387113875
|| ( p > parse_start + 1
13872-
&& isALPHA_A(*(p - 1))
13876+
&& strpbrk(p-1, "NpPbBxog") == p-1
1387313877
&& *(p - 2) == '\\')
1387413878
|| new_regcurly(p, RExC_end))
1387513879
{
@@ -14390,7 +14394,12 @@ S_regatom(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth)
1439014394
/* Position parse to next real character */
1439114395
skip_to_be_ignored_text(pRExC_state, &RExC_parse,
1439214396
FALSE /* Don't force to /x */ );
14393-
if (PASS2 && *RExC_parse == '{' && OP(ret) != SBOL && ! regcurly(RExC_parse)) {
14397+
if (PASS2
14398+
&& *RExC_parse == '{'
14399+
&& OP(ret) != SBOL
14400+
&& ! regcurly(RExC_parse)
14401+
&& strpbrk(RExC_parse-1, "NpPbBxog") == RExC_parse-1) /* [cperl #362] */
14402+
{
1439414403
ckWARNregdep(RExC_parse + 1, "Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through");
1439514404
}
1439614405

t/re/reg_mesg.t

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,17 @@ my @death =
302302
'/(?[\ |!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[\ |!{#}])/', # [perl #126180]
303303
'/(?[()-!])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[(){#}-!])/', # [perl #126204]
304304
'/(?[!()])/' => 'Incomplete expression within \'(?[ ])\' {#} m/(?[!(){#}])/', # [perl #126404]
305-
'/\w{/' => 'Unescaped left brace in regex is illegal here {#} m/\w{{#}/',
306-
'/\q{/' => 'Unescaped left brace in regex is illegal here {#} m/\q{{#}/',
307-
'/\A{/' => 'Unescaped left brace in regex is illegal here {#} m/\A{{#}/',
305+
#'/\N{/' => 'Missing right brace on \\N{} or unescaped left brace after \\N ... {#} m/\N{{#}/', # [cperl #362]
306+
'/\p{/' => 'Missing right brace on \\p{} {#} m/\p{{#}/', # [cperl #362]
307+
'/\P{/' => 'Missing right brace on \\P{} {#} m/\P{{#}/', # [cperl #362]
308+
'/\b{/' => 'Missing right brace on \\b{} {#} m/\b{{#}/', # [cperl #362]
309+
'/\B{/' => 'Missing right brace on \\B{} {#} m/\B{{#}/', # [cperl #362]
310+
'/\x{/' => 'Missing right brace on \\x{} {#} m/\\x{{#}/', # [cperl #362]
311+
'/\o{/' => 'Missing right brace on \\o{ {#} m/\\o{{#}/', # [cperl #362]
312+
'/\g{/' => 'Sequence \\g{... not terminated {#} m/\\g{{#}/', # [cperl #362]
313+
#'/\w{/' => 'Unescaped left brace in regex is illegal here {#} m/\w{{#}/',
314+
#'/\q{/' => 'Unescaped left brace in regex is illegal here {#} m/\q{{#}/',
315+
#'/\A{/' => 'Unescaped left brace in regex is illegal here {#} m/\A{{#}/',
308316
'/(?<=/' => 'Sequence (?... not terminated {#} m/(?<={#}/', # [perl #128170]
309317
'/\p{vertical tab}/' => 'Can\'t find Unicode property definition "vertical tab" {#} m/\\p{vertical tab}{#}/', # [perl #132055]
310318

@@ -686,13 +694,13 @@ my @deprecated = (
686694
'/^{/' => "",
687695
'/foo|{/' => "",
688696
'/foo|^{/' => "",
689-
'/foo({bar)/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through {#} m/foo({{#}bar)/',
697+
#'/foo({bar)/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through {#} m/foo({{#}bar)/',
690698
'/foo(:?{bar)/' => "",
691699
'/\s*{/' => "",
692700
'/a{3,4}{/' => "",
693-
'/.{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/.{{#}/',
694-
'/[x]{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/[x]{{#}/',
695-
'/\p{Latin}{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/\p{Latin}{{#}/',
701+
#'/.{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/.{{#}/',
702+
#'/[x]{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/[x]{{#}/',
703+
#'/\p{Latin}{/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through {#} m/\p{Latin}{{#}/',
696704
);
697705

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

0 commit comments

Comments
 (0)