6
$\begingroup$

Bug fixed in 12.2.0


Tested with versions 9.0.0, 10.0.2 and 10.3.0, all under OS X 10.10.5. and Linux

The drag-and-drop front-end functionality also results in $Failed.

Surprisingly, Importing, JPEGs, TXTs, and XLSX work just fine!

(* Initialization *)
SetDirectory[NotebookDirectory[]];
text = "Uh oh, this could be a bug";
fileNameTemplate = StringTemplate["s`1`mple file.`2`"];
extensions = { "pdf", "txt", "jpeg", "xlsx"};

$CharacterEncoding

"UTF-8"

(* The list of "a"s used in the test *)
Table[FromCharacterCode@a, {a, 1, 1000}];
as = Select[%, RemoveDiacritics@# == "a" &]

{"a", "à", "á", "â", "ã", "ä", "å", "ā", "ă", "ą", "ǎ", "ǟ", "ǡ", "ǻ", "ȁ", "ȃ", "ȧ", "ɐ", "ɑ", "ɒ"}

(* Exporting files, no failures so far *)
Map[# -> Export[fileNameTemplate @@ #, text] &, Outer[List, as, extensions], {2}]

{a,pdf}->sample file.pdf,
{a,txt}->sample file.txt,
{a,jpeg}->sample file.jpeg,
{a,xlsx}->sample file.xlsx
[...]
{ɒ,pdf}->sɒmple file.pdf,
[...]
{ɒ,xlsx}->sɒmple file.xlsx

(* Re-importing files *)
res = Map[# -> Import@# &, GatherBy[FileNames["*file*"], FileBaseName], {2}];
Drop[res, -1];
%[[-4 ;; -3, 1 ;; 4]] // Flatten // Column

sample file.jpeg-> #image here#
sample file.pdf->{#image here#}
sample file.txt->Uh oh, this could be a bug
sample file.xlsx->{{{Uh oh, this could be a bug}}}
sɐmple file.jpeg-> #image here#
sɐmple file.pdf->$Failed
sɐmple file.txt->Uh oh, this could be a bug
sɐmple file.xlsx->{{{Uh oh, this could be a bug}}}

Only PDFs fail. I've tried a bunch of different $CharacterEncodings, but the only solution so far was to rename the file, work with it, then rename it back, as in this (very rudimentary) example

withFunnyName[filePath_, fun_] := 
 Module[{origName = filePath, tempName, res},
  tempName = CreateTemporary[];
  DeleteFile[tempName];
  RenameFile[origName, tempName];
  res = fun@tempName;
  RenameFile[tempName, origName];
  res

]

What could I be doing wrong? Some system configurations?

$\endgroup$
4
  • 4
    $\begingroup$ This would seem to be a bug to me, and it can be tested most simply by the fact that Import[Export["test_ǡ.png", "Hello"]] works while Import[Export["test_ǡ.pdf", "Hello"]] returns $Failed $\endgroup$
    – Jason B.
    Feb 12, 2016 at 13:16
  • $\begingroup$ I suspected that, but I'm always wary of blaming the system... (You actually came! Thanks!) $\endgroup$
    – Aisamu
    Feb 18, 2016 at 19:04
  • $\begingroup$ Dedicated thread: "How to workaround failures with Unicode filepaths?" $\endgroup$ Apr 30, 2017 at 8:12
  • $\begingroup$ With Mathematica 12.2.0 on Windows I don't reproduce the bug aymore, so finally it seems to be fixed. $\endgroup$ Mar 6, 2021 at 20:10

0