Commits

Anonymous committed e5e555e

Added a unit test, fixed an issue in the core unittest with ipv6-enabled systems and fixed an issue in parseRequestLine() when URL paths contained spaces (or anything that would split on a space)

* Added a encoded URL unittest to test/test_core.py
* Fixed lib/httptools.py's parseRequestLine() to not barf when the request line did not unpack to three values (i.e., if the path contained spaces)
* Fixed the logging test in test_core.py to fix an issue where the logger would log ipv6 addresses.

Comments (0)

Files changed (2)

cherrypy/lib/httptools.py

 
 def parseRequestLine(requestLine):
     """Return (method, path, querystring, protocol) from a requestLine."""
-    method, path, protocol = requestLine.split()
-    
+    splitLine = requestLine.split()
+    method, protocol = splitLine[0], splitLine[-1]
+    path = " ".join(splitLine[1:-1])
+
     # path may be an abs_path (including "http://host.domain.tld");
     # Ignore scheme, location, and fragments (so config lookups work).
     # [Therefore, this assumes all hosts are valid for this server.]

cherrypy/test/test_core.py

 
     cherrypy.root.divorce = Divorce()
 
+    class Encoded:
+        def default(self, *args):
+            return "Encoded response"
+        default.exposed = True
+
+    cherrypy.root.encoded = Encoded()
 
     class Cookies(Test):
         
         self.assertStatus(200)
         
         data = open(log_access_file, "rb").readlines()
-        self.assertEqual(data[0][:15], '127.0.0.1 - - [')
+        address = data[0].split()[0]
+        if address not in ['127.0.0.1', '::ffff:127.0.0.1', '::1']:
+            self.fail('access log did not contain remote IP:\n%s' % (data[0]))
+          
         haslength = False
         for k, v in self.headers:
             if k.lower() == 'content-length':
             self.assert_(data[0].endswith('] "GET %s/flatten/as_string HTTP/1.1" 200 - "" ""\n'
                                           % self.prefix()))
         
-        self.assertEqual(data[1][:15], '127.0.0.1 - - [')
+        address = data[1].split()[0]
+        if address not in ['127.0.0.1', '::ffff:127.0.0.1', '::1']:
+            self.fail('access log did not contain remote IP:\n%s' % (data[0]))
+
         haslength = False
         for k, v in self.headers:
             if k.lower() == 'content-length':
             results.append(self.body)
         self.assertEqual(results, ["None"] * 20)
     
+    def testEncodedURL(self):
+        self.getPage('/encoded/%0Ax')
+        self.assertBody("Encoded response")
+
     def testDefaultContentType(self):
         self.getPage('/')
         self.assertHeader('Content-Type', 'text/html')