diff options
author | Yves Orton <demerphq@gmail.com> | 2013-06-12 21:03:50 +0200 |
---|---|---|
committer | Yves Orton <demerphq@gmail.com> | 2013-06-12 21:20:33 +0200 |
commit | b75763d608047188e76fcf5249a427b3ad13e87a (patch) | |
tree | 40a79acc590d5a7aac882ebebadeb7f1612d6002 | |
parent | d7bfa5540b75a5472143ac2ff07153f261b4b075 (diff) | |
download | perl-b75763d608047188e76fcf5249a427b3ad13e87a.tar.gz |
do not warn when optimizing away /x{0,0}?+/ and /x{0,0}+/
In c37d14f947f7998211b0455e453160fb7e15b22e Karl fixed an issue
reported in [perl #118375] "5.18 regex regression Quantifier follows nothing in regex"
but he fixed only the non-greedy modifier mentioned in the ticket,
and did not include support for the other quantifier modifiers like the
non-greedy possessive (stupid but not illegal), and the possessive
(useful) modifiers.
Hopefully this covers them all.
Note that because Karl already included support for m/x {0,0} ?/x
I have done so as well for the new cases. I do not necessarily endorse
the idea that it is legal or should be tested for. I am inclined to
think that '{0,0}?+' should be indivisible even under /x.
-rw-r--r-- | regcomp.c | 13 | ||||
-rw-r--r-- | t/re/re_tests | 6 |
2 files changed, 16 insertions, 3 deletions
@@ -9700,9 +9700,16 @@ S_regpiece(pTHX_ RExC_state_t *pRExC_state, I32 *flagp, U32 depth) } ret = reg_node(pRExC_state, NOTHING); - /* But the quantifier includes any '?' (the non-greedy - * modifier) after the {}, [perl #118375] */ - if (RExC_parse < RExC_end && *RExC_parse == '?') { + /* But the quantifier includes any '?', the non-greedy + * modifier, after the {}, [perl #118375] + * Likewise the '+', the possessive modifier, and + * they can be combined too, '?+' is the possessive + * non-greedy modifier. + */ + if (RExC_parse < RExC_end && *RExC_parse == '?' ) { + nextchar(pRExC_state); + } + if (RExC_parse < RExC_end && *RExC_parse == '+' ) { nextchar(pRExC_state); } return ret; diff --git a/t/re/re_tests b/t/re/re_tests index ae28e141e1..45018df71b 100644 --- a/t/re/re_tests +++ b/t/re/re_tests @@ -1744,4 +1744,10 @@ m?^xy\?$? xy? y $& xy? /(a|(bc)){0,0}?xyz/ xyz y $& xyz /( a | ( bc ) ) {0,0} ? xyz/x xyz y $& xyz +/(a|(bc)){0,0}+xyz/ xyz y $& xyz +/( a | ( bc ) ) {0,0} + xyz/x xyz y $& xyz + +/(a|(bc)){0,0}?xyz/ xyz y $& xyz +/( a | ( bc ) ) {0,0} ? + xyz/x xyz y $& xyz + # vim: softtabstop=0 noexpandtab |