develooper Front page | perl.perl5.porters | Postings from September 2010

Re: [perl #77084] scalar //g match on overloaded object causesstring corruption

Thread Previous
From:
Abigail
Date:
September 2, 2010 02:55
Subject:
Re: [perl #77084] scalar //g match on overloaded object causesstring corruption
Message ID:
20100902095547.GA16764@almanda
On Wed, Sep 01, 2010 at 05:16:07PM +0100, Dave Mitchell wrote:
> On Thu, Aug 19, 2010 at 06:38:08PM +0200, Abigail wrote:
> > On Sun, Aug 08, 2010 at 02:36:31PM -0700, Father Chrysostomos wrote:
> > > use Data::Dumper;
> > > use overoad q/""/=>sub{"foo:bar"};
> > > bless [], =~ /(.*)/g;
> > > $Data::Dumper::Useqq++;
> > > print Dumper "$1";
> > > __END__
> > > 
> > > The output varies, but it’s usually something like:
> > > 
> > > $VAR1 = "\t\0\0\0\263\337!";
> > 
> > I can confirm this.
> > Included a TODO test for this in commit a9f6cb1.
> 
> This is now partially fixed with commit
> 
>     f427b557f0f598ee6ff57dfc24080cf33d959242
> 
> More to the point, this fixes the original bug report, but doesn't pass
> all the tests in t/re/overload.t. In particular, the pos() position after
> the second (scalar) match is attached to $o, and re-used for the third
> match (void), which then matches the zero-length string at the end.
> 
> I think this is correct behaviour and that the third test is wrong.
> Opinions?

You are right. I've fixed this by setting pos ($o) = 0 after
the second test. (commit f3a0defb95e2da85126a0bd17bf5d67899fff9b3).

> PS Abigail: why was a new test file created for this rather than just
> adding to lib/overload.t ?

No particular reason. I was looking for an appropriate test file in t/re,
and didn't find one. Hence a new file. But since it's an issue about the
interaction of regexes and overloading, putting in in lib/overload.t works
as well.


Abigail

Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About