Esteemed Monks,
I am searching for unicode-filenames on disk with File::Find::Rule in this way:
use utf8; use Test::More; use Test2::Plugin::UTF8; use Devel::Peek; use Encode; use File::Find::Rule; # the file's 1st letter is greek kappa, # 2nd letter is iota accented (with tonos) my $expected = 'test/κί.png'; my @gots = map { Encode::decode_utf8($_) } File::Find::Rule->file()->name(qr/.*\.png/)->in('test') ; is(scalar(@gots), 1, "got 1 item"); is($gots[0], $expected, "name is as expected"); Dump($expected); Dump($gots[0]); done_testing();
Dir 'test' contains one file: κί.png (κί.png, kappa, iota accented dot png).
In Linux, the above succeeds and prints the filenames as:
FLAGS = (POK,IsCOW,pPOK,UTF8) PV = 0x561260048d00 "test/\xCE\xBA\xCE\xAF.png"\0 [UTF8 "test/\x{3ba +}\x{3af}.png"] CUR = 13 LEN = 15 FLAGS = (POK,IsCOW,pPOK,UTF8) PV = 0x561260249060 "test/\xCE\xBA\xCE\xAF.png"\0 [UTF8 "test/\x{3ba +}\x{3af}.png"] CUR = 13 LEN = 15
In OSX (10.13 high sierra whatever), it fails and it prints:
FLAGS = (POK,IsCOW,pPOK,UTF8) PV = 0x7fd35e7d8b60 "test/\316\272\316\257.png"\0 [UTF8 "test/\x{3ba +}\x{3af}.png"] CUR = 13 LEN = 15 FLAGS = (POK,IsCOW,pPOK,UTF8) PV = 0x7fd35e7ee4e0 "test/\316\272\316\271\314\201.png"\0 [UTF8 "tes +t/\x{3ba}\x{3b9}\x{301}.png"] CUR = 15 LEN = 17
The difference is that in Linux the "greek iota with tonos (accented)" is just 1 character: U+03AF (hex \x{3af}). And this comes out both when I typed it in the script (the $expected) and when File::Find::Rule found the corresponding file on disk.
In OSX however, the expected value is just as in linux. But File::Find::Rule finds the file on disk and its name is now : kappa, iota and *separate* accent (\x{3ba}\x{3b9}\x{301}). It looks the same but test fails.
Additional info:
The raw output of File::Find::Rule is:
OSX: PV = 0x7f8724885690 "test/\316\272\316\271\314\201.png"\0 <<<< se +parate accent Linux: PV = 0x5566b6bc05d0 "test/\xCE\xBA\xCE\xAF.png"\0
So, it seems the culprit is File::Find::Rule who adds the separate accent.
The program works find I guess because the OS treats these filenames with accented unicode chars correctly. What's bothering me is that my tests fail.
Am I doing things wrong? I need some advice.
bw, bliako
5min Edit: changed the title
In reply to File::Find::Rule returns different filenames if they have chars with accents: OSX vs Linux by bliako
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |