develooper Front page | perl.perl5.porters | Postings from October 2017

[perl #132224] File test operators erroneously break on upgradedstrings

Thread Next
From:
perlbug-followup
Date:
October 5, 2017 23:19
Subject:
[perl #132224] File test operators erroneously break on upgradedstrings
Message ID:
rt-4.0.24-8118-1507242059-154.132224-75-0@perl.org
# New Ticket Created by   
# Please include the string:  [perl #132224]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=132224 >



This is a bug report for perl from dbook@cpan.org,
generated with the help of perlbug 1.40 running under perl 5.26.0.


-----------------------------------------------------------------
[Please describe your issue here]

File test operators like -e and -f appear to be using the
internal representation of the file path passed to them, or are
otherwise broken by upgrading the string when it contains
non-ASCII bytes. It seems unreasonable to expect users to
downgrade any file paths passed to these operators just in case
it was accidentally upgraded; the expected behavior would be to
use the perl-level representation of the string. Reproduction
case below, or at https://perlbot.pl/raw/l2vc6w .

use strict;
use warnings;

use Encode 'encode';
use File::Spec::Functions 'catfile';
use File::Temp;
use Test::More;

my $filename = "t\x{eb}st";

my $dir = File::Temp->newdir;

my $filepath = catfile $dir, encode('UTF-8', $filename);
open my $fh, '>', $filepath or die "Failed to create file $filepath: $!";
close $fh;

ok -e $filepath, "File $filepath exists";
utf8::upgrade $filepath;
ok -e $filepath, "File $filepath still exists"; # this fails

done_testing;

__END__
ok 1 - File /tmp/GnS7A2ORvG/tëst exists
not ok 2 - File /tmp/GnS7A2ORvG/tëst still exists
#   Failed test 'File /tmp/GnS7A2ORvG/tëst still exists'
#   at test_filename.pl line 19.
1..2
# Looks like you failed 1 test of 2.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl 5.26.0:

Configured by grinnz at Tue May 30 17:37:21 EDT 2017.

Summary of my perl5 (revision 5 version 26 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=4.8.13-100.fc23.x86_64
    archname=x86_64-linux
    uname='linux home.grinnz.com 4.8.13-100.fc23.x86_64 #1 smp fri dec 9 14:51:40 utc 2016 x86_64 x86_64 x86_64 gnulinux '
    config_args='-Dprefix=/home/grinnz/.plenv/versions/5.26.0 -de -Dusedevel -A'eval:scriptdir=/home/grinnz/.plenv/versions/5.26.0/bin''
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='5.3.1 20160406 (Red Hat 5.3.1-6)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64 /usr/local/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.22.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.22'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    Devel::PatchPerl 1.38

---
@INC for perl 5.26.0:
    /home/grinnz/.plenv/versions/5.26.0/lib/perl5/site_perl/5.26.0/x86_64-linux
    /home/grinnz/.plenv/versions/5.26.0/lib/perl5/site_perl/5.26.0
    /home/grinnz/.plenv/versions/5.26.0/lib/perl5/5.26.0/x86_64-linux
    /home/grinnz/.plenv/versions/5.26.0/lib/perl5/5.26.0

---
Environment for perl 5.26.0:
    HOME=/home/grinnz
    LANG=en_US.utf8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/grinnz/.plenv/versions/5.26.0/bin:/home/grinnz/.plenv/libexec:/home/grinnz/.plenv/plugins/perl-build/bin:/home/grinnz/.plenv/plugins/plenv-contrib/bin:/home/grinnz/.plenv/shims:/home/grinnz/.plenv/bin:/usr/local/cuda/bin:/home/grinnz/.plenv/bin:/usr/local/cuda/bin:/usr/local/bin:/usr/bin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/fish


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