From: Alex Vandiver Date: Wed, 15 Apr 2009 17:04:23 +0000 (-0400) Subject: Data::Dumper hash iterator needs to be reset on all hashrefs (fixes #64744) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b36d99fa001e5d6abe733b5f320d6ec15529756b;p=p5sagit%2Fp5-mst-13.2.git Data::Dumper hash iterator needs to be reset on all hashrefs (fixes #64744) --- diff --git a/ext/Data-Dumper/Dumper.pm b/ext/Data-Dumper/Dumper.pm index b716ff2..0852dd4 100644 --- a/ext/Data-Dumper/Dumper.pm +++ b/ext/Data-Dumper/Dumper.pm @@ -231,11 +231,6 @@ sub Dumpperl { $name = "\$" . $s->{varname} . $i; } - # Ensure hash iterator is reset - if (ref($val) eq 'HASH') { - keys(%$val); - } - my $valstr; { local($s->{apad}) = $s->{apad}; @@ -429,6 +424,10 @@ sub _dump { $keys = [ sort keys %$val ]; } } + + # Ensure hash iterator is reset + keys(%$val); + while (($k, $v) = ! $sortkeys ? (each %$val) : @$keys ? ($key = shift(@$keys), $val->{$key}) : () ) diff --git a/ext/Data-Dumper/t/bugs.t b/ext/Data-Dumper/t/bugs.t index ad58d6a..453b252 100644 --- a/ext/Data-Dumper/t/bugs.t +++ b/ext/Data-Dumper/t/bugs.t @@ -16,7 +16,7 @@ BEGIN { } use strict; -use Test::More tests => 4; +use Test::More tests => 5; use Data::Dumper; { @@ -57,7 +57,22 @@ ok(1, "[perl #38612]"); # Still no core dump? We are fine. my $txt = $d->Dump(); my $VAR1; eval $txt; - is_deeply($VAR1, \%h, '[perl #40668] Reset hash iterator'); + is_deeply($VAR1, \%h, '[perl #40668] Reset hash iterator'); +} + +# [perl #64744] Data::Dumper each() bad interaction +{ + local $Data::Dumper::Useqq = 1; + my $a = {foo => 1, bar => 1}; + each %$a; + $a = {x => $a}; + + my $d = Data::Dumper->new([$a]); + $d->Useqq(1); + my $txt = $d->Dump(); + my $VAR1; + eval $txt; + is_deeply($VAR1, $a, '[perl #64744] Reset hash iterator'); } # [perl #56766] Segfaults on bad syntax - fixed with version 2.121_17