Robert Brewer avatar Robert Brewer committed 867656a

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

Comments (0)

Files changed (2)

cherrypy/lib/http.py

     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:

cherrypy/test/test_core.py

         self.assertBody("da\n"
                         "en-gb;q=0.8\n"
                         "en;q=0.7")
+        
+        # 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.
         self.getPage("/headers/Content-Type",
                      headers=[("Content-type", "application/json")])
         self.assertBody("application/json")
-        
+    
     def testHTTPMethods(self):
         helper.webtest.methods_with_bodies = ("POST", "PUT", "PROPFIND")
         
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.