Skip to content

Commit

Permalink
Test malformed utf8 filenames roundtripping properly
Browse files Browse the repository at this point in the history
Fixes RT#127671. Please feel free to object these tests (using similar
concerns raised in the ticket). However, I still can't see how
something in a subdirectory of /tmp can create a problem for any
user. To me it sounds like nothing should ever touch or see these
files anyway.
  • Loading branch information
AlexDaniel committed Feb 2, 2018
1 parent e2dc8f0 commit a7590d6
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion S32-str/utf8-c8.t
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use Test;
# 8-bit octet stream given to us by OSes that don't promise anything about
# the character encoding of filenames and so forth.

plan 59;
plan 63;

{
my $test-str;
Expand Down Expand Up @@ -177,6 +177,26 @@ is Buf.new(0xFE).decode('utf8-c8').chars, 1, 'Decoding Buf with just 0xFE works'
$fh.close;
}

# RT#127671
if $*DISTRO.is-win {
skip('Not clear if there is an alternative to this issue on Windows', 4);
} else {
my $test-dir = $*TMPDIR ~ '/tmp.' ~ $*PID ~ '-' ~ time;
mkdir $test-dir;
# ↑ normal directory in TMPDIR to hide our scary stuff
my $file = ("$test-dir/".encode ~ Buf.new(0x06, 0xAB)).decode('utf8-c8');
# ↑ a file with a name that is somewhat weird
END { try unlink $file; try rmdir $test-dir }
spurt $file, 'hello'; # create the file
lives-ok {
my @files = $test-dir.IO.dir;
is @files.elems, 1, 'dir returns something when encountering malformed utf8 names';
my $roundtrip = @files[0].basename.encode('utf8-c8');
is-deeply $roundtrip.list, (0x06, 0xAB), 'utf8-c8 name roundtripped through dir';
is @files.IO.slurp, 'hello', 'can slurp a file with utf8-c8 name';
}, 'dir lives with malformed utf8 names';
}

# MoarVM #664
# UTF8-C8 string changes under concatenation/substr
{
Expand Down

0 comments on commit a7590d6

Please sign in to comment.