develooper Front page | perl.perl5.porters | Postings from July 2016

[perl #128524] Data::Dumper gets string lengths wrong when the utf8flag is set

Thread Previous
From:
Karen Etheridge
Date:
July 2, 2016 22:00
Subject:
[perl #128524] Data::Dumper gets string lengths wrong when the utf8flag is set
Message ID:
rt-4.0.18-30829-1467496844-862.128524-75-0@perl.org
# New Ticket Created by  Karen Etheridge 
# Please include the string:  [perl #128524]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=128524 >


seen in both Data::Dumper 2.154 and 2.160, perl 5.24.0 and perl 5.25.0.

Here is a self-contained reproduction case showing that string lengths are being counted wrong:

use strict;                                                                                                         
use warnings;                                                                                                       
                                                                                                                    
my $runtime = 'runtime';                                                                                            
my $requires = 'requires';                                                                                          
                                                                                                                    
utf8::upgrade($runtime);                                                                                            
utf8::upgrade($requires);                                                                                           
                                                                                                                    
my $data = {
    $runtime => {
        $requires => { 'foo' => 'bar' }
    }              
};                                                                                                                  
                                                                                                                    
use Data::Dumper;                                                                                                   
                                                                                                                    
print Data::Dumper->new( [$data], ['x'] )->Purity(1)->Sortkeys(1)->Terse(0)->Dump() . "\n";                         

__END__
got:
$x = {
       'runtime' => {
                    'requires' => {
                                  'foo' => 'bar'                                                                    
                                }
                  }
     };

but the output should instead be:
$x = {
       'runtime' => {
                      'requires' => {
                                      'foo' => 'bar'                                                                
                                    }
                    }
     };


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