From: yves orton Date: Fri, 17 Nov 2006 10:17:48 +0000 (-0800) Subject: [perl #18209] bug in regex s/\s$word\s/ /gi; and $& X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a678b0e43642b70fc74cc90fbae9fc1913934001;p=p5sagit%2Fp5-mst-13.2.git [perl #18209] bug in regex s/\s$word\s/ /gi; and $& From: "yves orton via RT" Message-ID: p4raw-id: //depot/perl@29312 --- diff --git a/mg.c b/mg.c index f82aa0d..67f1453 100644 --- a/mg.c +++ b/mg.c @@ -497,9 +497,18 @@ Perl_magic_regdata_cnt(pTHX_ SV *sv, MAGIC *mg) if (PL_curpm) { register const REGEXP * const rx = PM_GETRE(PL_curpm); if (rx) { - return mg->mg_obj - ? rx->nparens /* @+ */ - : rx->lastparen; /* @- */ + if (mg->mg_obj) { /* @+ */ + /* return the number possible */ + return rx->nparens; + } else { /* @- */ + I32 paren = rx->lastparen; + + /* return the last filled */ + while ( paren >= 0 && + rx->startp[paren] == -1 || rx->endp[paren] == -1) + paren--; + return (U32)paren; + } } } diff --git a/t/op/pat.t b/t/op/pat.t index 8f2ce2a..e206af7 100755 --- a/t/op/pat.t +++ b/t/op/pat.t @@ -4064,6 +4064,13 @@ for my $c ("z", "\0", "!", chr(254), chr(256)) { } } { + local $Message = "RT#22614"; + local $_='ab'; + our @len=(); + /(.){1,}(?{push @len,0+@-})(.){1,}(?{})^/; + iseq("@len","2 2 2"); +} +{ local $Message = "RT#18209"; my $text = ' word1 word2 word3 word4 word5 word6 ';