Skip to content

Commit

Permalink
zipfile: Fix regression that broke handling of zipfiles with internal…
Browse files Browse the repository at this point in the history
… filenames not encoded in UTF-8. Fixes #1860889 [Decoding fails when opening a file with a specific file name in the viewer](https://bugs.launchpad.net/calibre/+bug/1860889)
  • Loading branch information
kovidgoyal committed Jan 26, 2020
1 parent 547fa08 commit 197a744
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/calibre/utils/zipfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from calibre import sanitize_file_name
from calibre.constants import filesystem_encoding
from calibre.ebooks.chardet import detect
from polyglot.builtins import unicode_type, string_or_bytes, getcwd, map
from polyglot.builtins import unicode_type, string_or_bytes, getcwd, map, as_bytes

try:
import zlib # We may need its compression method
Expand Down Expand Up @@ -327,8 +327,12 @@ def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
# This is used to ensure paths in generated ZIP files always use
# forward slashes as the directory separator, as required by the
# ZIP format specification.
if os.sep != "/" and os.sep in filename:
filename = filename.replace(os.sep, "/")
if os.sep != '/':
os_sep, sep = os.sep, '/'
if isinstance(filename, bytes):
os_sep, sep = as_bytes(os_sep), b'/'
if os_sep in filename:
filename = filename.replace(os_sep, sep)

self.filename = filename # Normalized file name
self.date_time = date_time # year, month, day, hour, min, sec
Expand Down

0 comments on commit 197a744

Please sign in to comment.