1. Walt Woods
  2. CherryPy_subhandler


Robert Brewer  committed 867656a

Fix for #763 (Exception when parsing Content-Type).

  • Participants
  • Parent commits 188a668
  • Branches default

Comments (0)

Files changed (2)

File cherrypy/lib/http.py

View file
  • Ignore whitespace
     if applied against a Python string, is requesting resource[3:7]. This
     function will return the list [(3, 7)].
-    If this function return an empty list, you should return HTTP 416.
+    If this function returns an empty list, you should return HTTP 416.
     if not headervalue:
         """Transform 'token;key=val' to ('token', {'key': 'val'})."""
         # Split the element into a value and parameters. The 'value' may
         # be of the form, "token=token", but we don't split that here.
-        atoms = [x.strip() for x in elementstr.split(";")]
+        atoms = [x.strip() for x in elementstr.split(";") if x.strip()]
         initial_value = atoms.pop(0).strip()
         params = {}
         for atom in atoms:

File cherrypy/test/test_core.py

View file
  • Ignore whitespace
+        # Test malformed header parsing. See http://www.cherrypy.org/ticket/763.
+        self.getPage("/headerelements/get_elements?headername=Content-Type",
+                     # Note the illegal trailing ";"
+                     headers=[('Content-Type', 'text/html; charset=utf-8;')])
+        self.assertStatus(200)
+        self.assertBody("text/html;charset=utf-8")
     def testHeaders(self):
         # Tests that each header only appears once, regardless of case.
                      headers=[("Content-type", "application/json")])
     def testHTTPMethods(self):
         helper.webtest.methods_with_bodies = ("POST", "PUT", "PROPFIND")