Give a sensible error message if the filename is invalid UTF-8

This commit is contained in:
Mark Haines 2015-08-26 17:27:23 +01:00
parent 5a9e0c3682
commit c9cb354b58
2 changed files with 8 additions and 2 deletions

View file

@ -155,7 +155,7 @@ class BaseMediaResource(Resource):
if upload_name:
upload_name = urlparse.unquote(upload_name)
try:
upload_name = upload_name.decode("utf-8");
upload_name = upload_name.decode("utf-8")
except UnicodeDecodeError:
upload_name = None
else:

View file

@ -86,7 +86,13 @@ class UploadResource(BaseMediaResource):
upload_name = request.args.get("filename", None)
if upload_name:
upload_name = upload_name[0].decode('UTF-8')
try:
upload_name = upload_name[0].decode('UTF-8')
except UnicodeDecodeError:
raise SynapseError(
msg="Invalid UTF-8 filename parameter: %r" % (upload_name),
code=400,
)
headers = request.requestHeaders