From: Jonathan Camp Date: Thu, 18 Oct 2012 08:32:45 +0000 (+0200) Subject: correctly handle empty POST parameters X-Git-Tag: v3.0.0~36^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c791984de4db5f661799ea926b4e174c3f6063c2;p=thirdparty%2Ftornado.git correctly handle empty POST parameters --- diff --git a/tornado/httputil.py b/tornado/httputil.py index 0f8a8438d..26b33cd0a 100644 --- a/tornado/httputil.py +++ b/tornado/httputil.py @@ -215,9 +215,8 @@ def parse_body_arguments(content_type, body, arguments, files): that will be updated with the parsed contents. """ if content_type.startswith("application/x-www-form-urlencoded"): - uri_arguments = parse_qs_bytes(native_str(body)) + uri_arguments = parse_qs_bytes(native_str(body), keep_blank_values=True) for name, values in uri_arguments.iteritems(): - values = [v for v in values if v] if values: arguments.setdefault(name, []).extend(values) elif content_type.startswith("multipart/form-data"): diff --git a/tornado/test/httpserver_test.py b/tornado/test/httpserver_test.py index 190f1abc3..7ee82b831 100644 --- a/tornado/test/httpserver_test.py +++ b/tornado/test/httpserver_test.py @@ -247,6 +247,8 @@ class EchoHandler(RequestHandler): def get(self): self.write(recursive_unicode(self.request.arguments)) + def post(self): + self.write(recursive_unicode(self.request.arguments)) class TypeCheckHandler(RequestHandler): def prepare(self): @@ -300,6 +302,11 @@ class HTTPServerTest(AsyncHTTPTestCase, LogTrapTestCase): data = json_decode(response.body) self.assertEqual(data, {u"foo": [u"\u00e9"]}) + def test_empty_post_parameters(self): + response = self.fetch("/echo", method="POST", body="foo=&bar=") + data = json_decode(response.body) + self.assertEqual(data, {u"foo": [u""], u"bar": [u""]}) + def test_types(self): headers = {"Cookie": "foo=bar"} response = self.fetch("/typecheck?foo=bar", headers=headers)