diff options
author | Erik Johnston <erik@matrix.org> | 2015-08-27 11:18:01 +0100 |
---|---|---|
committer | Erik Johnston <erik@matrix.org> | 2015-08-27 11:18:01 +0100 |
commit | 4a6d89485095d61d020089a0e7e0a74848cf511d (patch) | |
tree | 5d6c671d215c90782a9d40d8e0c938ed39a67fa3 /synapse/rest | |
parent | None check the correct variable (diff) | |
parent | Consistency (diff) | |
download | synapse-4a6d89485095d61d020089a0e7e0a74848cf511d.tar.xz |
Merge pull request #260 from matrix-org/erikj/filename_order
Check for an internationalised filename first
Diffstat (limited to 'synapse/rest')
-rw-r--r-- | synapse/rest/media/v1/base_resource.py | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/synapse/rest/media/v1/base_resource.py b/synapse/rest/media/v1/base_resource.py index 610cb3ef82..b2aeb8c909 100644 --- a/synapse/rest/media/v1/base_resource.py +++ b/synapse/rest/media/v1/base_resource.py @@ -145,14 +145,20 @@ class BaseMediaResource(Resource): content_disposition = headers.get("Content-Disposition", None) if content_disposition: _, params = cgi.parse_header(content_disposition[0],) - upload_name = params.get("filename", None) - if upload_name and not is_ascii(upload_name): - upload_name = None - else: - upload_name_utf8 = params.get("filename*", None) - if upload_name_utf8: - if upload_name_utf8.lower().startswith("utf-8''"): - upload_name = upload_name_utf8[7:] + upload_name = None + + # First check if there is a valid UTF-8 filename + upload_name_utf8 = params.get("filename*", None) + if upload_name_utf8: + if upload_name_utf8.lower().startswith("utf-8''"): + upload_name = upload_name_utf8[7:] + + # If there isn't check for an ascii name. + if not upload_name: + upload_name_ascii = params.get("filename", None) + if upload_name_ascii and is_ascii(upload_name_ascii): + upload_name = upload_name_ascii + if upload_name: upload_name = urlparse.unquote(upload_name) try: |