Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

fix incorrect encoding of filenames with spaces in #2090

Merged
merged 7 commits into from
Mar 11, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions synapse/rest/media/v1/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,17 @@ def respond_with_file(request, media_type, file_path,
if os.path.isfile(file_path):
request.setHeader(b"Content-Type", media_type.encode("UTF-8"))
if upload_name:
if is_ascii(upload_name):
richvdh marked this conversation as resolved.
Show resolved Hide resolved
request.setHeader(
b"Content-Disposition",
b"inline; filename=%s" % (
urllib.quote(upload_name.encode("utf-8")),
),
)
else:
request.setHeader(
b"Content-Disposition",
b"inline; filename*=utf-8''%s" % (
urllib.quote(upload_name.encode("utf-8")),
),
)
# technically we should only use the crazy *=utf-8'' syntax
# if the filename actually contains utf-8. but if we don't, some
# browsers (Firefox 52, Safari 10, Chrome at some point < 57) get it
# get it wrong and return %20 verbatim rather than url-decoding it
# causing bug https://github.com/vector-im/riot-web/issues/3155
request.setHeader(
b"Content-Disposition",
b"inline; filename*=utf-8''%s" % (
urllib.quote(upload_name.encode("utf-8")),
),
)

# cache for at least a day.
# XXX: we might want to turn this off for data we don't want to
Expand Down