Anonymous avatar Anonymous committed 66a1c79

Leading slash no longer omitted from path_info when parsing an absolute URI. Fixes #1061. [Python 3]

Comments (0)

Files changed (2)

py3/cherrypy/test/test_request_obj.py

                 setattr(root, name.lower(), cls())
         class Test(object, metaclass=TestType):
             pass
-        
-        
+
+        class PathInfo(Test):
+
+            def default(self, *args):
+                return cherrypy.request.path_info
+
         class Params(Test):
             
             def index(self, thing):
     def test_scheme(self):
         self.getPage("/scheme")
         self.assertBody(self.scheme)
-    
+
+    def testRelativeURIPathInfo(self):
+        self.getPage("/pathinfo/foo/bar")
+        self.assertBody("/pathinfo/foo/bar")
+
+    def testAbsoluteURIPathInfo(self):
+        # http://cherrypy.org/ticket/1061
+        self.getPage("http://localhost/pathinfo/foo/bar")
+        self.assertBody("/pathinfo/foo/bar")
+
     def testParams(self):
         self.getPage("/params/?thing=a")
         self.assertBody("'a'")

py3/cherrypy/wsgiserver/__init__.py

         """
         if uri == b"*":
             return None, None, uri
-        
-        i = uri.find(b'://')
-        if i > 0 and b'?' not in uri[:i]:
+
+        scheme, sep, remainder = uri.partition(b'://')
+        if sep and b'?' not in scheme:
             # An absoluteURI.
             # If there's a scheme (and it must be http or https), then:
             # http_URL = "http:" "//" host [ ":" port ] [ abs_path [ "?" query ]]
-            scheme, remainder = uri[:i].lower(), uri[i + 3:]
-            authority, path = remainder.split(b"/", 1)
-            return scheme, authority, path
-        
+            authority, path_a, path_b = remainder.partition(b'/')
+            return scheme.lower(), authority, path_a+path_b
+
         if uri.startswith(b'/'):
             # An abs_path.
             return None, None, uri
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.