From bf0d502bcd5c443a4178f1c239692976c0f5f185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=2E=20K=C3=A4rkk=C3=A4inen?= Date: Fri, 23 Aug 2019 12:18:48 +0300 Subject: [PATCH] Unquote filenames also in normal mode. --- sanic/request.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sanic/request.py b/sanic/request.py index c3c44729..0defb07f 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -558,13 +558,14 @@ def parse_multipart_form(body, boundary): if form_header_field == "content-disposition": field_name = form_parameters.get("name") file_name = form_parameters.get("filename") - + encoding = content_charset # non-ASCII filenames in RFC2231, "filename*" format if file_name is None and form_parameters.get("filename*"): - encoding, _, value = email.utils.decode_rfc2231( + encoding, _, file_name = email.utils.decode_rfc2231( form_parameters["filename*"] ) - file_name = unquote(value, encoding=encoding) + if file_name is not None: + file_name = unquote(file_name, encoding=encoding) elif form_header_field == "content-type": content_type = form_header_value content_charset = form_parameters.get("charset", "utf-8")