diff options
author | Karl Williamson <khw@cpan.org> | 2019-03-23 10:16:16 -0600 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2019-03-23 10:24:26 -0600 |
commit | d9a91485293e1414746fd028b3782f699519105e (patch) | |
tree | c0d66956e1e009f7c4286f913df74cb11deea632 | |
parent | 39ce401c1db32fe69d69d11cfd7b62071e52f43a (diff) | |
download | perl-d9a91485293e1414746fd028b3782f699519105e.tar.gz |
PATCH: [perl #132851] Empty /(?)/
This changes perlre to note that zero modifiers are allowed in the
(?...) construct, but changes the code to warn about this no-op, but
only under "use re 'strict'".
-rw-r--r-- | pod/perldiag.pod | 5 | ||||
-rw-r--r-- | pod/perlre.pod | 6 | ||||
-rw-r--r-- | regcomp.c | 6 | ||||
-rw-r--r-- | t/re/reg_mesg.t | 1 |
4 files changed, 17 insertions, 1 deletions
diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 8163dde583..7a3faad3ca 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -2169,6 +2169,11 @@ C<\x> without specifying anything for it to operate on. Unfortunately, for backwards compatibility reasons, an empty C<\x> is legal outside S<C<use re 'strict'>> and expands to a NUL character. +=item Empty (?) without any modifiers in regex; marked by <-- HERE in m/%s/ + +(W regexp) (only under C<S<use re 'strict'>>) +C<(?)> does nothing, so perhaps this is a typo. + =item ${^ENCODING} is no longer supported (F) The special variable C<${^ENCODING}>, formerly used to implement diff --git a/pod/perlre.pod b/pod/perlre.pod index f9ea161700..cc717075ac 100644 --- a/pod/perlre.pod +++ b/pod/perlre.pod @@ -1376,7 +1376,7 @@ an escape sequence. Examples: =item C<(?^alupimnsx)> X<(?)> X<(?^)> -One or more embedded pattern-match modifiers, to be turned on (or +Zero or more embedded pattern-match modifiers, to be turned on (or turned off if preceded by C<"-">) for the remainder of the pattern or the remainder of the enclosing pattern group (if any). @@ -1450,6 +1450,10 @@ C<(?-d:...)> and C<(?dl:...)> are fatal errors. Note also that the C<"p"> modifier is special in that its presence anywhere in a pattern has a global effect. +Having zero modifiers makes this a no-op (so why did you specify it, +unless it's generated code), and starting in v5.30, warns under L<C<use +re 'strict'>|re/'strict' mode>. + =item C<(?:I<pattern>)> X<(?:)> @@ -11977,6 +11977,12 @@ S_reg(pTHX_ RExC_state_t *pRExC_state, I32 paren, I32 *flagp, U32 depth) RExC_parse--; /* for vFAIL to print correctly */ vFAIL("Sequence (? incomplete"); break; + + case ')': + if (RExC_strict) { /* [perl #132851] */ + ckWARNreg(RExC_parse, "Empty (?) without any modifiers"); + } + /* FALLTHROUGH */ default: /* e.g., (?i) */ RExC_parse = (char *) seqstart + 1; parse_flags: diff --git a/t/re/reg_mesg.t b/t/re/reg_mesg.t index 3d60c4a5dc..f8265924a2 100644 --- a/t/re/reg_mesg.t +++ b/t/re/reg_mesg.t @@ -673,6 +673,7 @@ my @warning_only_under_strict = ( "/[$low_mixed_digit-$high_mixed_digit]/" => "Ranges of ASCII printables should be some subset of \"0-9\", \"A-Z\", or \"a-z\" {#} m/[$low_mixed_digit-$high_mixed_digit\{#}]/", '/\b<GCB}/' => 'Unescaped literal \'}\' {#} m/\b<GCB}{#}/', '/[ ]def]/' => 'Unescaped literal \']\' {#} m/[ ]def]{#}/', + '/(?)/' => 'Empty (?) without any modifiers {#} m/(?){#}/', [perl #132851] ); my @warning_utf8_only_under_strict = mark_as_utf8( |