From 821a55c4aac907a41f3eadc26e1c4154a484e3e6 Mon Sep 17 00:00:00 2001 From: Irsyad Asyhari Lubis Date: Wed, 26 Jul 2017 17:42:16 +0700 Subject: [PATCH] Fix issue with parsing multipart body from unirest Some libraries e.g. unirest always put Content-Type inside every chunk. Even though, it is a simple text/plain. This makes Sanic, mistakenly, treats that chunk as file. This commit made sure only chunks with "filename" after Content-Disposition are treated as files. --- sanic/request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sanic/request.py b/sanic/request.py index 27ff011e..dc8722ad 100644 --- a/sanic/request.py +++ b/sanic/request.py @@ -265,7 +265,7 @@ def parse_multipart_form(body, boundary): if 'filename' in form_parameters: file_name = form_parameters['filename'] field_name = form_parameters.get('name') - elif form_header_field == 'content-type': + elif form_header_field == 'content-type' and file_name: file_type = form_header_value post_data = form_part[line_index:-4]