This commit is contained in:
ed 2021-03-27 02:44:40 +01:00
parent 3b354447b0
commit b12131e91c
4 changed files with 15 additions and 12 deletions

View file

@ -1,6 +1,6 @@
# coding: utf-8 # coding: utf-8
VERSION = (0, 10, 0) VERSION = (0, 10, 1)
CODENAME = "zip it" CODENAME = "zip it"
BUILD_DT = (2021, 3, 27) BUILD_DT = (2021, 3, 27)

View file

@ -1090,15 +1090,17 @@ class HttpCli(object):
) )
bascii = unicode(string.ascii_letters + string.digits).encode("utf-8") bascii = unicode(string.ascii_letters + string.digits).encode("utf-8")
chcon = ord if PY2 else int ufn = fn.encode("utf-8", "xmlcharrefreplace")
ufn = b"".join( if PY2:
[ ufn = [unicode(x) if x in bascii else "%{:02x}".format(ord(x)) for x in ufn]
else:
ufn = [
chr(x).encode("utf-8") chr(x).encode("utf-8")
if x in bascii if x in bascii
else "%{:02x}".format(chcon(x)).encode("ascii") else "%{:02x}".format(x).encode("ascii")
for x in fn.encode("utf-8", "xmlcharrefreplace") for x in ufn
] ]
).decode("ascii") ufn = b"".join(ufn).decode("ascii")
cdis = "attachment; filename=\"{}.{}\"; filename*=UTF-8''{}.{}" cdis = "attachment; filename=\"{}.{}\"; filename*=UTF-8''{}.{}"
cdis = cdis.format(afn, fmt, ufn, fmt) cdis = cdis.format(afn, fmt, ufn, fmt)

View file

@ -85,7 +85,7 @@ def gen_hdr(h_pos, fn, sz, lastmod, utf8, crc32, pre_crc):
ret += struct.pack("<LL", vsz, vsz) ret += struct.pack("<LL", vsz, vsz)
# windows support (the "?" replace below too) # windows support (the "?" replace below too)
fn = sanitize_fn(fn) fn = sanitize_fn(fn, "/")
bfn = fn.encode("utf-8" if utf8 else "cp437", "replace").replace(b"?", b"_") bfn = fn.encode("utf-8" if utf8 else "cp437", "replace").replace(b"?", b"_")
z64_len = len(z64v) * 8 + 4 if z64v else 0 z64_len = len(z64v) * 8 + 4 if z64v else 0

View file

@ -576,11 +576,12 @@ def undot(path):
return "/".join(ret) return "/".join(ret)
def sanitize_fn(fn): def sanitize_fn(fn, ok=""):
if "/" not in ok:
fn = fn.replace("\\", "/").split("/")[-1] fn = fn.replace("\\", "/").split("/")[-1]
if WINDOWS: if WINDOWS:
for bad, good in [ for bad, good in [x for x in [
["<", ""], ["<", ""],
[">", ""], [">", ""],
[":", ""], [":", ""],
@ -590,7 +591,7 @@ def sanitize_fn(fn):
["|", ""], ["|", ""],
["?", ""], ["?", ""],
["*", ""], ["*", ""],
]: ] if x[0] not in ok]:
fn = fn.replace(bad, good) fn = fn.replace(bad, good)
bad = ["con", "prn", "aux", "nul"] bad = ["con", "prn", "aux", "nul"]