Shushan Chai uploaded a change:
https://go-review.googlesource.com/9381
rchive/zip: use utf8 encoding for non ASCII filename
If FileHeader.Flags Bit11 is not set, filename use different local
encoding on different platform.
For example, in chinese Win7 use GBK, in chinese OSX use utf8.
This change will force the non ASCII filename use utf8 encoding.
https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
See Zip Spec 4.4.4 and APPENDIX D.
Change-Id: I27d2c3b15b01e844edab9c3875742633ee8a38ad
---
M src/archive/zip/writer.go
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/archive/zip/writer.go b/src/archive/zip/writer.go
index 87ac694..957b110 100644
--- a/src/archive/zip/writer.go
+++ b/src/archive/zip/writer.go
@@ -11,6 +11,7 @@
"hash"
"hash/crc32"
"io"
+ "unicode/utf8"
)
// TODO(adg): support zip file comments
@@ -204,6 +205,11 @@
}
}
+ // if filename contains non ASCII character, force use utf8 encoding
+ if utf8.RuneCount([]byte(fh.Name)) != len(fh.Name) {
+ fh.Flags |= 1 << 11
+ }
+
fh.Flags |= 0x8 // we will write a data descriptor
fh.CreatorVersion = fh.CreatorVersion&0xff00 | zipVersion20 // preserve
compatibility byte
--
https://go-review.googlesource.com/9381