develooper Front page | perl.perl5.porters | Postings from February 2012

Re: [perl #109828] PerlIO::scalar does not handle UTF-8

Thread Previous | Thread Next
From:
Eric Brine
Date:
February 14, 2012 09:42
Subject:
Re: [perl #109828] PerlIO::scalar does not handle UTF-8
Message ID:
CALJW-qFDJPRwYOcPCqBoUDYVM-XcKq+RG9_eH89Os7VG8vUG1A@mail.gmail.com
On Sun, Feb 12, 2012 at 5:02 PM, Father Chrysostomos via RT <
perlbug-followup@perl.org> wrote:

> That it is currently buggy is not being questioned.


And the following test will detect regressions once its fixed.

=====

use strict;
use warnings;

use Test::More tests => 1;

sub read_from_scalar {
    my ($file, $perlio) = @_;
    $perlio //= '';
    open my $fh, "<$perlio", \$file or die $!;
    local $/;
    return <$fh>;
}

sub hexify { join ' ', map sprintf('%02X', ord), split //, $_[0] }

{
    my $s = chr(0xE9);
    utf8::upgrade(   my $u = $s );
    utf8::downgrade( my $d = $s );
    is( hexify(read_from_scalar($u)), hexify(read_from_scalar($d)),
'Unicode bug in :scalar read' );
}

1;

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