In perl.git, the branch blead has been updated <https://perl5.git.perl.org/perl.git/commitdiff/0367231ce260cd08bcb13082d510e5778668bcc1?hp=3f04a46618bddd5191b797b7dac053fa581a91eb>
- Log ----------------------------------------------------------------- commit 0367231ce260cd08bcb13082d510e5778668bcc1 Author: Karl Williamson <[email protected]> Date: Thu Jan 4 12:53:29 2018 -0700 Raise deprecation for qr/(?foo})/ An unescaped left brace that is meant to be taken literally is officially deprecated, though there are no plans to remove it in contexts where we don't expect to use it to mean something else, and no warning is raised in those contexts. reg_mesg.t tests the known set of these contexts, currently (after this commit): /^{/ /foo|{/ /foo|^{/ /foo(:?{bar)/ /\s*{/ /a{3,4}{/ This commit deprecates this context: /foo({bar})/ This probably should have been illegal all along when 'bar' is a valid quantifier, as we do with the other quantifiers that follow a left paren whose illegality we haven't already taken advantage of to mean something else: qr/(+0)/ Quantifier follows nothing in regex This deprecation will allow ({...}) to be usable for a possible future regex extension ----------------------------------------------------------------------- Summary of changes: pod/perldelta.pod | 11 +++++++++++ pod/perldeprecation.pod | 50 ++++++++++++++++++++++++++----------------------- pod/perldiag.pod | 4 +++- regcomp.c | 12 +++++++++++- t/re/reg_mesg.t | 2 +- 5 files changed, 53 insertions(+), 26 deletions(-) diff --git a/pod/perldelta.pod b/pod/perldelta.pod index dc3c84ecad..2779f3d1d4 100644 --- a/pod/perldelta.pod +++ b/pod/perldelta.pod @@ -88,6 +88,17 @@ but preceded by some kind of explicit deprecation. Some uses of these already are illegal after a previous deprecation cycle. This deprecates the remaining uses. See L<perldeprecation>. +=head2 Use of unescaped C<"{"> immediately after a C<"("> + +Using unescaped left braces is officially deprecated everywhere, but it +is not enforced in contexts where their use does not interfere with +expected extensions to the language. A deprecation is added in this +release when the brace appears immediately after an opening parenthesis. +Before this, even if the brace was part of a legal quantifier, it was +not interpreted as such, but as the literal characters, unlike other +quantifiers that follow a C<"("> which are considered errors. Now, +their use will raise a deprecation message, unless turned off. + =head1 Performance Enhancements =over 4 diff --git a/pod/perldeprecation.pod b/pod/perldeprecation.pod index 8cd3eb950f..a00ceac76f 100644 --- a/pod/perldeprecation.pod +++ b/pod/perldeprecation.pod @@ -84,6 +84,31 @@ something useful. To avoid these bugs, the function is being made strict. Passing arguments was deprecated in Perl 5.28, and will become fatal in Perl 5.32. +=head3 Unescaped left braces in regular expressions + +The simple rule to remember, if you want to match a literal C<{> +character (U+007B C<LEFT CURLY BRACKET>) in a regular expression +pattern, is to escape each literal instance of it in some way. +Generally easiest is to precede it with a backslash, like C<\{> +or enclose it in square brackets (C<[{]>). If the pattern +delimiters are also braces, any matching right brace (C<}>) should +also be escaped to avoid confusing the parser, for example, + + qr{abc\{def\}ghi} + +Forcing literal C<{> characters to be escaped will enable the Perl +language to be extended in various ways in future releases. To avoid +needlessly breaking existing code, the restriction is is not enforced in +contexts where there are unlikely to ever be extensions that could +conflict with the use there of C<{> as a literal. + +Literal uses of C<{> were deprecated in Perl 5.20, and some uses of it +started to give deprecation warnings since. These cases were made fatal +in Perl 5.26. Due to an oversight, not all cases of a use of a literal +C<{> got a deprecation warning. Some cases started warning in Perl 5.26, +and they will be fatal by Perl 5.30. Other case started in Perl 5.28, +and will be made fatal in 5.32. + =head2 Perl 5.30 =head3 C<< $* >> is no longer supported @@ -132,30 +157,9 @@ disappear in Perl 5.30. Code using C<< File::Glob::glob() >> should call C<< File::Glob::bsd_glob() >> instead. +=head3 Unescaped left braces in regular expressions (for 5.30) -=head3 Unescaped left braces in regular expressions - -The simple rule to remember, if you want to match a literal C<{> -character (U+007B C<LEFT CURLY BRACKET>) in a regular expression -pattern, is to escape each literal instance of it in some way. -Generally easiest is to precede it with a backslash, like C<\{> -or enclose it in square brackets (C<[{]>). If the pattern -delimiters are also braces, any matching right brace (C<}>) should -also be escaped to avoid confusing the parser, for example, - - qr{abc\{def\}ghi} - -Forcing literal C<{> characters to be escaped will enable the Perl -language to be extended in various ways in future releases. To avoid -needlessly breaking existing code, the restriction is is not enforced in -contexts where there are unlikely to ever be extensions that could -conflict with the use there of C<{> as a literal. - -Literal uses of C<{> were deprecated in Perl 5.20, and some uses of it -started to give deprecation warnings since. These cases were made fatal -in Perl 5.26. Due to an oversight, not all cases of a use of a literal -C<{> got a deprecation warning. These cases started warning in Perl 5.26, -and they will be fatal by Perl 5.30. +See L</Unescaped left braces in regular expressions> above. =head3 Unqualified C<dump()> diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 889375d0a6..c9e5c9b014 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -6361,6 +6361,8 @@ Check the #! line, or manually feed your script into Perl yourself. =item Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.30), passed through in regex; marked by S<<-- HERE> in m/%s/ +=item Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through in regex; marked by S<<-- HERE> in m/%s/ + (D deprecated, regexp) The simple rule to remember, if you want to match a literal C<{> character (U+007B C<LEFT CURLY BRACKET>) in a regular expression pattern, is to escape each literal instance of it in @@ -6382,7 +6384,7 @@ still just deprecated. This is because of an oversight: some uses of a literal C<{> that should have raised a deprecation warning starting in v5.20 did not warn until v5.26. By making the already-warned uses fatal now, some of the planned extensions can be made to the language sooner. -The cases which are still allowed will be fatal in Perl 5.30. +The cases which are still allowed will be fatal in Perl 5.30 or 5.32. The contexts where no warnings or errors are raised are: diff --git a/regcomp.c b/regcomp.c index 06ebf37ea3..54f9fad0ff 100644 --- a/regcomp.c +++ b/regcomp.c @@ -11421,7 +11421,16 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth) goto parse_rest; } /* end switch */ } - else if (!(RExC_flags & RXf_PMf_NOCAPTURE)) { /* (...) */ + else { + if (*RExC_parse == '{' && PASS2) { + ckWARNregdep(RExC_parse + 1, + "Unescaped left brace in regex is " + "deprecated here (and will be fatal " + "in Perl 5.32), passed through"); + } + /* Not bothering to indent here, as the above 'else' is temporary + * */ + if (!(RExC_flags & RXf_PMf_NOCAPTURE)) { /* (...) */ capturing_parens: parno = RExC_npar; RExC_npar++; @@ -11447,6 +11456,7 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp,U32 depth) paren = ':'; ret = NULL; } + } } else /* ! paren */ ret = NULL; diff --git a/t/re/reg_mesg.t b/t/re/reg_mesg.t index a8aa65103c..ad18de0aae 100644 --- a/t/re/reg_mesg.t +++ b/t/re/reg_mesg.t @@ -677,7 +677,7 @@ my @deprecated = ( '/^{/' => "", '/foo|{/' => "", '/foo|^{/' => "", - '/foo({bar)/' => "", + '/foo({bar)/' => 'Unescaped left brace in regex is deprecated here (and will be fatal in Perl 5.32), passed through {#} m/foo({{#}bar)/', '/foo(:?{bar)/' => "", '/\s*{/' => "", '/a{3,4}{/' => "", -- Perl5 Master Repository
