]> Cypherpunks repositories - gostls13.git/commit
archive/zip: add FileHeader.NonUTF8 field
authorJoe Tsai <joetsai@digital-static.net>
Thu, 2 Nov 2017 20:53:16 +0000 (13:53 -0700)
committerJoe Tsai <thebrokentoaster@gmail.com>
Mon, 6 Nov 2017 21:35:59 +0000 (21:35 +0000)
commit4fcc835971ad63cf913ebe074ef6191e35a44ab9
tree21b132a256d3f8652416b9eb9d4a4fe5a25473d5
parent0c554957483aaf1f62c6251dbe62ab5fce3e219c
archive/zip: add FileHeader.NonUTF8 field

The NonUTF8 field provides users with a way to explictly tell the
ZIP writer to avoid setting the UTF-8 flag.
This is necessary because many readers:
1) (Still) do not support UTF-8
2) And use the local system encoding instead

Thus, even though character encodings other than CP-437 and UTF-8
are not officially supported by the ZIP specification, pragmatically
the world has permitted use of them.

When a non-standard encoding is used, it is the user's responsibility
to ensure that the target system is expecting the encoding used
(e.g., producing a ZIP file you know is used on a Chinese version of Windows).

We adjust the detectUTF8 function to account for Shift-JIS and EUC-KR
not being identical to ASCII for two characters.

We don't need an API for users to explicitly specify that they are encoding
with UTF-8 since all single byte characters are compatible with all other
common encodings (Windows-1256, Windows-1252, Windows-1251, Windows-1250,
IEC-8859, EUC-KR, KOI8-R, Latin-1, Shift-JIS, GB-2312, GBK) except for
the non-printable characters and the backslash character (all of which
are invalid characters in a path name anyways).

Fixes #10741

Change-Id: I9004542d1d522c9137973f1b6e2b623fa54dfd66
Reviewed-on: https://go-review.googlesource.com/75592
Run-TryBot: Joe Tsai <thebrokentoaster@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/archive/zip/reader.go
src/archive/zip/reader_test.go
src/archive/zip/struct.go
src/archive/zip/testdata/utf8-7zip.zip [new file with mode: 0644]
src/archive/zip/testdata/utf8-infozip.zip [new file with mode: 0644]
src/archive/zip/testdata/utf8-osx.zip [new file with mode: 0644]
src/archive/zip/testdata/utf8-winrar.zip [new file with mode: 0644]
src/archive/zip/testdata/utf8-winzip.zip [new file with mode: 0644]
src/archive/zip/writer.go
src/archive/zip/writer_test.go