summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-10-07 04:37:22 +0000
committerpje <pje@571e12c6-e1fa-0310-aee7-ff1267fa46bd>2004-10-07 04:37:22 +0000
commit80ab7d7dca091ade937e91fb84d552c344f4e6ad (patch)
tree5a6b9a3c949fbbd2cbe1b0f49d2001e18f6abc14
parentb60e8cd5700a11062b3a4a46fe212932e18cc2c3 (diff)
downloadwsgiref-80ab7d7dca091ade937e91fb84d552c344f4e6ad.tar.gz
Fix an edge case in path shifting/traversal: if SCRIPT_NAME is '' and
PATH_INFO is '/', then shifting should yield an empty name, SCRIPT_INFO should become '/', and PATH_INFO should become ''. This breaks the normal rules about SCRIPT_NAME never ending with '/', and some tests needed updating for this. git-svn-id: svn://svn.eby-sarna.com/svnroot/wsgiref@253 571e12c6-e1fa-0310-aee7-ff1267fa46bd
-rw-r--r--src/wsgiref/tests/test_util.py6
-rw-r--r--src/wsgiref/util.py16
2 files changed, 11 insertions, 11 deletions
diff --git a/src/wsgiref/tests/test_util.py b/src/wsgiref/tests/test_util.py
index b406841..2b82db6 100644
--- a/src/wsgiref/tests/test_util.py
+++ b/src/wsgiref/tests/test_util.py
@@ -59,7 +59,7 @@ class UtilityTests(TestCase):
def testSimpleShifts(self):
- self.checkShift('','/', '', '', '')
+ self.checkShift('','/', '', '/', '')
self.checkShift('','/x', 'x', '/x', '')
self.checkShift('/','', None, '/', '')
self.checkShift('/a','/x/y', 'x', '/a/x', '/y')
@@ -74,8 +74,8 @@ class UtilityTests(TestCase):
self.checkShift('/a/b', '/./y', 'y', '/a/b/y', '')
self.checkShift('/a/b', '/./y/', 'y', '/a/b/y', '/')
self.checkShift('/a/b', '///./..//y/.//', '..', '/a', '/y/')
- self.checkShift('/a/b', '///', '', '/a/b', '')
- self.checkShift('/a/b', '/.//', '', '/a/b', '')
+ self.checkShift('/a/b', '///', '', '/a/b/', '')
+ self.checkShift('/a/b', '/.//', '', '/a/b/', '')
self.checkShift('/a/b', '/x//', 'x', '/a/b/x', '/')
self.checkShift('/a/b', '/.', None, '/a/b', '')
diff --git a/src/wsgiref/util.py b/src/wsgiref/util.py
index 1a8bd9a..dac492d 100644
--- a/src/wsgiref/util.py
+++ b/src/wsgiref/util.py
@@ -86,10 +86,14 @@ def shift_path_info(environ):
If there are no remaining path segments in PATH_INFO, return None.
Note: 'environ' is modified in-place; use a copy if you need to keep
the original PATH_INFO or SCRIPT_NAME.
- """
+ Note: when PATH_INFO is just a '/', this returns '' and appends a trailing
+ '/' to SCRIPT_NAME, even though empty path segments are normally ignored,
+ and SCRIPT_NAME doesn't normally end in a '/'. This is intentional
+ behavior, to ensure that an application can tell the difference between
+ '/x' and '/x/' when traversing to objects.
+ """
path_info = environ.get('PATH_INFO','')
-
if not path_info:
return None
@@ -102,6 +106,8 @@ def shift_path_info(environ):
script_name = posixpath.normpath(script_name+'/'+name)
if script_name.endswith('/'):
script_name = script_name[:-1]
+ if not name and not script_name.endswith('/'):
+ script_name += '/'
environ['SCRIPT_NAME'] = script_name
environ['PATH_INFO'] = '/'.join(path_parts)
@@ -113,14 +119,8 @@ def shift_path_info(environ):
# an empty string in the environ.
if name=='.':
name = None
-
return name
-
-
-
-
-
def setup_testing_defaults(environ):
"""Update 'environ' with trivial defaults for testing purposes