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

Commit e89910f

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] (cherry picked from commit 17e2b8d)
1 parent 11c7bd6 commit e89910f

File tree

5 files changed

+78
-17
lines changed

5 files changed

+78
-17
lines changed

.git-rr-cache

Submodule .git-rr-cache updated 253 files

pod/perlcdelta.pod

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,28 @@ returned hek, which does the downgrading to bytes already.
4747

4848
=back
4949

50+
=head1 Deprecations
51+
52+
=head2 Undeprecate "Unescaped left brace in regex" warnings and errors
53+
54+
In cperl only the following special unicode groups within regexes are reserved:
55+
56+
Name: \N{
57+
Property: \p{ \P{
58+
Break: \b{ \B{
59+
Code: \x{ \o{
60+
Group: \g{
61+
62+
All other C</{}/> sequences are allowed in cperl and not deprecated
63+
anymore. There's no need to quote the literal C<\{> and C<\}>, only if
64+
it's ambiguous and can be mixed up with those reserved unicode groups.
65+
66+
B<automake> and more widespread utils does not need to be plagued by
67+
spurious "Unescaped left brace in regex" warnings, when they dont need
68+
to be quoted. We undeprecated those new warnings and errors, there's
69+
nothing more to reserve (yet).
70+
L<[cperl #362]|https://github.com/perl11/cperl/issues/362>
71+
5072
=head1 Modules and Pragmata
5173

5274
=head2 Updated Modules and Pragmata

pod/perldiag.pod

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

67436745
The contexts where no warnings or errors are raised are:
67446746

@@ -6766,6 +6768,16 @@ as the first character following a quantifier
67666768

67676769
/\s*{/
67686770

6771+
=item *
6772+
6773+
in cperl only if the unicode group is one of the following reserved:
6774+
6775+
Name: /\N{/
6776+
Property: /\p{/ /\P{/
6777+
Break: /\b{/ /\B{/
6778+
Code: /\x{/ /\o{/
6779+
Group: /\g{/
6780+
67696781
=back
67706782

67716783
=for comment
@@ -6825,6 +6837,16 @@ as the first character following a quantifier
68256837

68266838
/\s*{/
68276839

6840+
=item *
6841+
6842+
in cperl only if the unicode group is one of the following reserved:
6843+
6844+
Name: /\N{/
6845+
Property: /\p{/ /\P{/
6846+
Break: /\b{/ /\B{/
6847+
Code: /\x{/ /\o{/
6848+
Group: /\g{/
6849+
68286850
=back
68296851

68306852
=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)