4

I'm on Debian. I have a file called Sóanr.jpg. According to https://emojidissector.com/, this is made of the following code points:

S   0053    LATIN CAPITAL LETTER S
o   006F    LATIN SMALL LETTER O
́   0301    COMBINING ACUTE ACCENT
a   0061    LATIN SMALL LETTER A
n   006E    LATIN SMALL LETTER N
r   0072    LATIN SMALL LETTER R

When I create a zip of this file, and then unzip it, the LATIN SMALL LETTER O and the COMBINING ACUTE ACCENT get put together into a new code point:

S   0053    LATIN CAPITAL LETTER S
ó   00F3    LATIN SMALL LETTER O WITH ACUTE
a   0061    LATIN SMALL LETTER A
n   006E    LATIN SMALL LETTER N
r   0072    LATIN SMALL LETTER R

This is not what I want. How do I preserve the original unicode code points?


EDIT: I was able to successfully zip and unzip following Stephen Kitt's example below. Yay! This is great news. However, I continue to have the above problem when using Nautilus right-click -> Extract Here.

If I extract my archive using Nautilus right-click -> Extract Here, my unicode characters come out changed as described above. So I guess Nautilus is not using unzip.

(How I create the zip doesn't seem to matter -- either with the zip command or with Nautilus's right-click -> Compress.)

The question becomes:

Is there a way to create a zip archive so that Nautilus' default unzipping program doesn't clobber my unicodes?

(And: How can I figure out what program Nautilus is using to Extract Here?)

Before zip:

$ ls S* | od -a -t x1
0000000   S   o   L soh   a   n   r   .   z   i   p  nl
         53  6f  cc  81  61  6e  72  2e  7a  69  70  0a

After right-click -> Extract Here:

$ ls S* | od -a -t x1
0000000   S   C   3   a   n   r   .   j   p   g  nl
         53  c3  b3  61  6e  72  2e  6a  70  67  0a
3
  • 2
    Please edit your question and show how exactly you check the encoding of the file names and how you create and extract the ZIP file.
    – Bodo
    Feb 2, 2023 at 10:07
  • Beware that xterm uses the precomposed versions of the characters (when available) for display as it's not able to compose characters yet by itself, and that's what you get when you copy-paste text from the screen. Feb 2, 2023 at 10:18
  • Other than that I find that neither Info-ZIP's zip nor bsdtar transform those characters when archiving or extracting zip files. Feb 2, 2023 at 10:20

1 Answer 1

2

You don’t need to do anything:

$ touch So<0301>anr.jpg

$ ls So* | od -a -t x1
0000000   S   o   L soh   a   n   r   .   j   p   g  nl
         53  6f  cc  81  61  6e  72  2e  6a  70  67  0a
0000014

$ zip -9 unitest.zip So*
  adding: Sóanr.jpg (stored 0%)

$ unzip -v unitest.zip | grep Stored | od -a -t x1
0000000  sp  sp  sp  sp  sp  sp  sp   0  sp  sp   S   t   o   r   e   d
         20  20  20  20  20  20  20  30  20  20  53  74  6f  72  65  64
0000020  sp  sp  sp  sp  sp  sp  sp  sp   0  sp  sp  sp   0   %  sp   0
         20  20  20  20  20  20  20  20  30  20  20  20  30  25  20  30
0000040   2   -   0   2   -   2   0   2   3  sp   1   2   :   2   6  sp
         32  2d  30  32  2d  32  30  32  33  20  31  32  3a  32  36  20
0000060   0   0   0   0   0   0   0   0  sp  sp   S   o   L soh   a   n
         30  30  30  30  30  30  30  30  20  20  53  6f  cc  81  61  6e
0000100   r   .   j   p   g  nl
         72  2e  6a  70  67  0a
0000106

This shows that the file name is stored as it was created. Extracting the file preserves the name:

$ rm So*

$ unzip unitest.zip
Archive:  unitest.zip
 extracting: Sóanr.jpg

$ ls So* | od -a -t x1
0000000   S   o   L soh   a   n   r   .   j   p   g  nl
         53  6f  cc  81  61  6e  72  2e  6a  70  67  0a
0000014

Nautilus doesn’t use unzip to extract archives, it uses libarchive. Other tools which use libarchive exhibit the same issue:

$ bsdtar -tf unitest.zip | od -a -t x1
0000000   S   C   3   a   n   r   .   j   p   g  nl
         53  c3  b3  61  6e  72  2e  6a  70  67  0a
0000013

I don’t see any relevant bug filed against libarchive (see the output of ldd /usr/bin/nautilus), you may want to open one after testing whether the latest release still behaves in this way.

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .