Commits

Anonymous committed bcaa527

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

  • Participants
  • Parent commits 9efa191

Comments (0)

Files changed (2)

File py2/cherrypy/py24compat.py

+"""
+Module that provides backward-compatible implementations of Python 2.5
+built-in capability. Named py24compat because when you no longer need Python
+2.4 compatibility, you can remove py24compat.
+"""
+import sys
+
+def _partition_py24(s, sep):
+    """ Returns a three element tuple, (head, sep, tail) where:
+
+        head + sep + tail == s
+        sep == '' or sep is t
+        bool(sep) == (t in s)       # sep indicates if the string was found
+
+    >>> s = 'http://www.python.org'
+    >>> partition(s, '://')
+    ('http', '://', 'www.python.org')
+    >>> partition(s, '?')
+    ('http://www.python.org', '', '')
+    >>> partition(s, 'http://')
+    ('', 'http://', 'www.python.org')
+    >>> partition(s, 'org')
+    ('http://www.python.', 'org', '')
+    """
+    if not isinstance(t, basestring) or not t:
+        raise ValueError('partititon argument must be a non-empty string')
+    parts = s.split(sep, 1)
+    if len(parts) == 1:
+        result = (s, '', '')
+    else:
+        result = (parts[0], sep, parts[1])
+    assert len(result) == 3
+    assert ''.join(result) == s
+    assert result[1] == '' or result[1] is sep
+    return result
+
+if sys.version_info >= (2,5):
+    partition = lambda s, sep: s.partition(sep)
+else:
+    partition = _partition_py24

File py2/cherrypy/wsgiserver/__init__.py

 
 import errno
 
+from cherrypy.py24compat import partition
+
 def plat_specific_errors(*errnames):
     """Return error numbers for all errors in errnames on this platform.
     
         if uri == "*":
             return None, None, uri
         
-        i = uri.find('://')
-        if i > 0 and '?' not in uri[:i]:
+        scheme, sep, remainder = partition(uri, '://')
+        if sep and '?' 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("/", 1)
-            return scheme, authority, path
+            authority, path_a, path_b = partition(remainder, '/')
+            return scheme.lower(), authority, path_a+path_b
         
         if uri.startswith('/'):
             # An abs_path.