15

Bug introduced in 12.1.0 and fixed in 12.2.0 (or 12.1.1?)


Could anybody help?

NotebookDirectory[] function began working wrong in 12.1 (the bug was not present in 12.0 and earlier versions).

When folder name includes Russian (Cyrillic) symbols, the function returns wrong path. Namely, the path contains all the folders up to the one including Сyrillics.

Example: if file path is "C:\folder1\folder2\папка\test.nb" NotebookDirectory[] returns "C:\folder1\folder2".

Any idea?

Alexey Popkov
  • 61,809
  • 7
  • 149
  • 368
Alexander
  • 151
  • 2
  • 1
    Next time, please do not use the [tag:bugs] tag when initially asking a question, until a different user is able to confirm that what you have observed is a bug. This time, I'll let it slide since ilian was able to provide confirmation. – J. M.'s missing motivation Apr 17 '20 at 04:08
  • Thanks for trying my idea, clearly it is not quite right so I'll delete the attempted answer for now. Could you tell me what is $CharacterEncoding on your system? – ilian Apr 17 '20 at 06:14
  • it returns the following: WindowsCyrillic – Alexander Apr 17 '20 at 06:24
  • I do not reproduce the bug with version 12.2.0 on Windows. – Alexey Popkov Mar 06 '21 at 19:53

1 Answers1

12

This is a certainly a bug. The fix for it is going to be available in the next release (version 12.1.1).

In the meantime, perhaps the following workaround code may help

Unprotect[Internal`EncodeCharacters];

Internal`EncodeCharacters[str_, enc_] := 
       Quiet[FromCharacterCode[ToCharacterCode[str], enc]]

(assuming it does, it could be placed in the kernel init.m file for convenience)

enter image description here

ilian
  • 25,474
  • 4
  • 117
  • 186
  • Dear Ilian, thank you for the answer! I place nb file directly at C: disk. On evaluating the suggested command and Notebookdirectory[] an error message appeared: "String expected at position 1 in DirectoryName[ByteArrayToString[StringToByteArray[D:\test.nb,Unicode],Unicode)]]. Could you please help with correcting the "patch"? – Alexander Apr 16 '20 at 21:44
  • Apologies, I am not on Windows at the moment. Please see if the updated variant seems to work. – ilian Apr 16 '20 at 22:02
  • Dear Ilian, thank you for these – Alexander Apr 17 '20 at 05:35
  • tryes to fix the bug. This is the next result: String expected at position 1 in DirectoryName[ ByteArrayToString[StringToByteArray[C : \test.nb, Unicode], Unicode]] That is, the same error message still appears – Alexander Apr 17 '20 at 05:36
  • 1
    Dear Ilian, I confirm that this patch works at my computer too. Thank you very much!!! – Alexander Apr 19 '20 at 10:46