From: Yves Orton Date: Sun, 17 Feb 2008 16:53:27 +0000 (+0000) Subject: Fix bug 50496 -- regcomp.c=~s/lastcloseparen/lastparen/g X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=250257bbff1fc2894d6e73059be5be21b4ea00a4;p=p5sagit%2Fp5-mst-13.2.git Fix bug 50496 -- regcomp.c=~s/lastcloseparen/lastparen/g -- lastcloseparen is literally the index of the last paren closed -- lastparen is index of the highest index paren that has been closed. In nested parens, they will be completely different. 'ab'=~/(a(b))/ will have: lastparen = 2, lastcloseparen = 1 'ab'=~/(a)(b)/ will have: lastparen = lastcloseparen = 2 p4raw-id: //depot/perl@33325 --- diff --git a/regcomp.c b/regcomp.c index c4313ae..5c05635 100644 --- a/regcomp.c +++ b/regcomp.c @@ -5042,6 +5042,7 @@ SV* Perl_reg_named_buff_nextkey(pTHX_ REGEXP * const r, const U32 flags) { struct regexp *const rx = (struct regexp *)SvANY(r); + GET_RE_DEBUG_FLAGS_DECL; PERL_ARGS_ASSERT_REG_NAMED_BUFF_NEXTKEY; @@ -5054,7 +5055,7 @@ Perl_reg_named_buff_nextkey(pTHX_ REGEXP * const r, const U32 flags) SV* sv_dat = HeVAL(temphe); I32 *nums = (I32*)SvPVX(sv_dat); for ( i = 0; i < SvIVX(sv_dat); i++ ) { - if ((I32)(rx->lastcloseparen) >= nums[i] && + if ((I32)(rx->lastparen) >= nums[i] && rx->offs[nums[i]].start != -1 && rx->offs[nums[i]].end != -1) { @@ -5114,7 +5115,7 @@ Perl_reg_named_buff_all(pTHX_ REGEXP * const r, const U32 flags) SV* sv_dat = HeVAL(temphe); I32 *nums = (I32*)SvPVX(sv_dat); for ( i = 0; i < SvIVX(sv_dat); i++ ) { - if ((I32)(rx->lastcloseparen) >= nums[i] && + if ((I32)(rx->lastparen) >= nums[i] && rx->offs[nums[i]].start != -1 && rx->offs[nums[i]].end != -1) { diff --git a/t/op/pat.t b/t/op/pat.t index 4d61068..599021f 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -3791,10 +3791,10 @@ sub iseq($$;$) { } } iseq($res,1,"$s~=/(?(?foo)\s+(?bar)?\s+(?baz))/"); - iseq($count,4,"Got 4 keys in %+ via each # TODO bug 50496"); - iseq(0+@k, 4, 'Got 4 keys in %+ via keys # TODO bug 50496'); - iseq("@k","A B C D", "Got expected keys # TODO bug 50496"); - iseq("@v","bar baz foo foo bar baz", "Got expected values # TODO bug = 50496"); + iseq($count,4,"Got 4 keys in %+ via each -- bug 50496"); + iseq(0+@k, 4, 'Got 4 keys in %+ via keys -- bug 50496'); + iseq("@k","A B C D", "Got expected keys -- bug 50496"); + iseq("@v","bar baz foo foo bar baz", "Got expected values -- bug = 50496"); eval' print for $+{this_key_doesnt_exist}; ';