develooper Front page | perl.perl5.porters | Postings from January 2013

[perl #112532] eval( Dumper( 'Latin1' ) ) can result in malformed UTF8

Thread Previous | Thread Next
From:
James E Keenan via RT
Date:
January 28, 2013 01:58
Subject:
[perl #112532] eval( Dumper( 'Latin1' ) ) can result in malformed UTF8
Message ID:
rt-3.6.HEAD-27190-1359338318-562.112532-15-0@perl.org
On Thu Apr 19 16:53:05 2012, sprout wrote:
> On Wed Apr 18 23:25:04 2012, zzbbyy wrote:
> > Dumper( "\x{f3}" ) returns a string encoded in Latin1. �This results
> > in malformed UTF8 when it is fed back to eval and 'use utf8' is in
> > force.
> > This is illustrated by the following test case:
> > 
> > use strict;
> > use warnings;
> > 
> > use utf8;
> > 
> > use Devel::Peek;
> > use Test::More;
> > use Data::Dumper;
> > $Data::Dumper::Terse = 1;
> > 
> > 
> > my $last = eval( Dumper( "\x{f3}" ) );
> > is( $last, "\x{f3}", 'eval' );
> > Dump( $last );
> > 
> > done_testing;
> > 
> > __OUTPUT__
> > 
> > not ok 1 - eval
> > # � Failed test 'eval'
> > # � at d.pl line 13.
> > Wide character in print at
> > /home/zby/localperl/lib/5.15.9/Test/Builder.pm line 1759.
> > # � � � � �got: '�'
> > # � � expected: 'ó'
> > SV = PV(0x21a4060) at 0x1ed1e40
> > �REFCNT = 1
> > �FLAGS = (PADMY,POK,pPOK,UTF8)
> > �PV = 0x2064050 "\363"\0Malformed UTF-8 character (1 byte, need 4,
> > after start byte 0xf3) in subroutine entry at d.pl line 14.
> > [UTF8 "\x{0}"]
> > �CUR = 1
> > �LEN = 16
> > 1..1
> > # Looks like you failed 1 test of 1.
> 
> The real bug here is that ‘eval’ is respecting the ‘use utf8’ from
> outside it.  Unfortunately, we cannot easily fix that without breaking
> code.  So, instead, we’ve added the unicode_eval feature in 5.16 (soon
> to be released).
> 
> If you put ‘use feature "unicode_eval"’ or ‘use v5.15’ (‘use v5.16’
> doesn’t yet work in bleadperl, because of the version number) at the top
> of your test script, it just works.
> 
> That the parser can produce malformed scalars is a separate bug, not
> specific to Data::Dumper or eval.  It can happen if you put ‘use utf8’
> at the top of a file that is not in utf8.  I thought that was already
> reported, but now I can’t find the ticket.
> 

I can confirm that Father C's suggestions work, so the OP's problem is
resolved as of Perl 5.16.

I propose that we close this ticket.  If someone wishes to discuss
whether the parser can produce malformed scalars, s/he should open a
separate ticket.

I am taking this ticket for the purpose of closing it in seven days
unless someone has new insights into these issues.

Thank you very much.
Jim Keenan


---
via perlbug:  queue: perl5 status: open
https://rt.perl.org:443/rt3/Ticket/Display.html?id=112532

Thread Previous | Thread Next


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