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

[perl #117355] [lu]cfirst don't respect 'use bytes'

Thread Previous | Thread Next
From:
Victor Efimov via RT
Date:
August 12, 2013 20:53
Subject:
[perl #117355] [lu]cfirst don't respect 'use bytes'
Message ID:
rt-3.6.HEAD-2552-1376340826-1735.117355-15-0@perl.org
On Sun Aug 11 19:56:53 2013, rjbs wrote:

And another edge case when perl unicode not working well, is filenames.

Code below prints that two strings are same. Tries to open file with
name defined by one string, and then to reopen file with name defined by
second string. Second attempt fail.

So that is another case when user might want to use bytes::xxx, 
_is_utf8() etc to access perl string internals, because internals
matters in this case.

(btw, I have a program which have to deal with non-UTF filesystems, this
makes things even worse. it has to pass _binary_ strings representing
filename across whole program and I should be very careful and never
merge it with ASCII strings with utf-8 bin or Unicode strings)

========

use Encode;
use utf8;
use strict;
use warnings;

my $u = "\x{442}\x{435}\x{441}\x{442}"; # same as "ั‚ะตัั‚"

# plain binary data, for example part of binary file (say, JPEG)
my $bin = "\xf1\xf2\xf3";

my $ascii = "x";
my ($ascii_u, undef) = split(/ /, "$ascii $u");
die unless utf8::is_utf8($ascii_u);

print "original bin length:\t";
print length($bin) . "\t" . bytes::length($bin) ."\n";

my $bin_a = $bin.$ascii;

print "bin_a length:\t";
print length($bin_a) . "\t" . bytes::length($bin_a) ."\n";

my $bin_u = $bin.$ascii_u; # THIS LINE CONTAINS A BUG

die unless $bin_u eq $bin_a;
print "bin_u and bin_a are same!\n";

open my $f, ">", "$bin_u.tmp";
binmode $f;
syswrite $f, "TEST";
close $f;

open $f, "<", "$bin_a.tmp" or die "file not found $!";
__END__
original bin length:    3       3
bin_a length:   4       4
bin_u and bin_a are same!
file not found No such file or directory at poc5.pl line 39.


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

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