fix filename when the filename have special characters
This commit is contained in:
parent
4a7a5c6f0c
commit
f351707290
3 changed files with 954 additions and 711 deletions
29
cgi.py
Normal file
29
cgi.py
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
def _parseparam(s):
|
||||||
|
while s[:1] == ';':
|
||||||
|
s = s[1:]
|
||||||
|
end = s.find(';')
|
||||||
|
while end > 0 and (s.count('"', 0, end) - s.count('\\"', 0, end)) % 2:
|
||||||
|
end = s.find(';', end + 1)
|
||||||
|
if end < 0:
|
||||||
|
end = len(s)
|
||||||
|
f = s[:end]
|
||||||
|
yield f.strip()
|
||||||
|
s = s[end:]
|
||||||
|
|
||||||
|
def parse_header(line):
|
||||||
|
"""Parse a Content-type like header.
|
||||||
|
Return the main content-type and a dictionary of options.
|
||||||
|
"""
|
||||||
|
parts = _parseparam(';' + line)
|
||||||
|
key = parts.__next__()
|
||||||
|
pdict = {}
|
||||||
|
for p in parts:
|
||||||
|
i = p.find('=')
|
||||||
|
if i >= 0:
|
||||||
|
name = p[:i].strip().lower()
|
||||||
|
value = p[i+1:].strip()
|
||||||
|
if len(value) >= 2 and value[0] == value[-1] == '"':
|
||||||
|
value = value[1:-1]
|
||||||
|
value = value.replace('\\\\', '\\').replace('\\"', '"')
|
||||||
|
pdict[name] = value
|
||||||
|
return key, pdict
|
||||||
4
main.py
4
main.py
|
|
@ -39,7 +39,6 @@ req_list = ("http://", "https://")
|
||||||
|
|
||||||
html_files = ("text/html", "application/xhtml+xml")
|
html_files = ("text/html", "application/xhtml+xml")
|
||||||
|
|
||||||
|
|
||||||
class Lifo(list):
|
class Lifo(list):
|
||||||
"""Limited size LIFO array to store messages and urls."""
|
"""Limited size LIFO array to store messages and urls."""
|
||||||
|
|
||||||
|
|
@ -175,6 +174,9 @@ class AngelBot(ClientXMPP):
|
||||||
if content_disposition:
|
if content_disposition:
|
||||||
_, params = cgi.parse_header(content_disposition)
|
_, params = cgi.parse_header(content_disposition)
|
||||||
filename = params.get("filename")
|
filename = params.get("filename")
|
||||||
|
if params.get("filename*"):
|
||||||
|
filename = params.get("filename*")
|
||||||
|
filename = filename.split("''")[-1]
|
||||||
else:
|
else:
|
||||||
filename = os.path.basename(uri.path)
|
filename = os.path.basename(uri.path)
|
||||||
|
|
||||||
|
|
|
||||||
1634
poetry.lock
generated
1634
poetry.lock
generated
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue