]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
correctly handle empty POST parameters 614/head
authorJonathan Camp <jonathan.camp@norman.com>
Thu, 18 Oct 2012 08:32:45 +0000 (10:32 +0200)
committerJonathan Camp <jonathan.camp@norman.com>
Thu, 18 Oct 2012 08:32:45 +0000 (10:32 +0200)
tornado/httputil.py
tornado/test/httpserver_test.py

index 0f8a8438d43582ac32a47cadf6e24fc0a2765ae3..26b33cd0a84acdfee5290f9da8c7754f0556819d 100644 (file)
@@ -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"):
index 190f1abc3bbd5a777eb16f10fb9aa2396514f423..7ee82b831085c69267f57dfd0d6793f837be8f34 100644 (file)
@@ -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)