Filename encoding inside zip

Hi everyone!

I want to zip a folder containing a file called “Livraison à blanc.doc”.
When I run my Zip task, the file name is twisted into “Livraison +à blanc.doc”.

I tested with gradle 2.14 and 3.1 in a Windows environment.

This is my gradle.properties file:
file.encoding=utf-8

I have specified in my task:
metadataCharset 'utf-8'

Please, what should I do to solve this problem?

1 Like

Hi, any chance you could provide a sample build that reproduce the issue?

This is my complete build file

Has someone any idea about the reason of this problem? I know I can rename the file, but I’d really like to understand why it has such a behaviour.

By the way, the problematic task is “livrer”.

From memory this detail is missing from the zip file format. Which encoding is used for metadata? (eg filenanes). Which charset does winzip assume? Which does 7zip assume? Is it different on unix vs Windows?

The safest solution is to avoid special chars in zip file names. Or you can set the metadataCharset but be wary that it might not read properly in all zip applications on all os’

Thx for your response!
The file name is encoded in ISO-8859-1. I’ve tried to run the build with file.encoding=ISO-8859-1 in the gradle.properties file. It still has the same behaviour.
However, in a Linux system, everything works fine.
How can I know which charset winzip and 7zip assume?

I’ve tried to run the build with file.encoding=ISO-8859-1

As I said you need to set the metadataCharset on the zip task. Perhaps try UTF-8 and CP-1252

How can I know which charset winzip and 7zip assume?

I’m not sure, since it’s missing from the zip spec I guess all zip applications make their own choice, you’ll have to look at the winzip/7zip docs. If I was to take an educated guess I’d say Linux zipping tools use UTF-8 and Windows zipping tools use CP-1252

This issue should be ringing alarm bells in your head. The safest solution is to avoid special chars in filenames. Why would you want to produce a zip that can only be unzipped by certain tools?

By using metadataCharset, the file is renamed into “Livraison Ó blanc”.
I know I should use standard characters only, but I’m studying if my company can replace Maven by Gradle. If the whole company makes a migration, I have to be sure there will be no regression and I’m sure we have plenty of special characters in our files metadata.