Merge "Fix bug with swob.Request.path_info_pop"

This commit is contained in:
Jenkins 2012-11-28 23:11:13 +00:00 committed by Gerrit Code Review
commit 02429858de
2 changed files with 15 additions and 1 deletions

View File

@ -758,10 +758,12 @@ class Request(object):
the path segment.
"""
path_info = self.path_info
if not path_info or path_info[0] != '/':
return None
try:
slash_loc = path_info.index('/', 1)
except ValueError:
return None
slash_loc = len(path_info)
self.script_name += path_info[:slash_loc]
self.path_info = path_info[slash_loc:]
return path_info[1:slash_loc]

View File

@ -300,6 +300,18 @@ class TestRequest(unittest.TestCase):
req = swift.common.swob.Request.blank('blahblah')
self.assertEquals(req.path_info_pop(), None)
def test_path_info_pop_last(self):
req = swift.common.swob.Request.blank('/last')
self.assertEquals(req.path_info_pop(), 'last')
self.assertEquals(req.path_info, '')
self.assertEquals(req.script_name, '/last')
def test_path_info_pop_none(self):
req = swift.common.swob.Request.blank('/')
self.assertEquals(req.path_info_pop(), '')
self.assertEquals(req.path_info, '')
self.assertEquals(req.script_name, '/')
def test_copy_get(self):
req = swift.common.swob.Request.blank(
'/hi/there', environ={'REQUEST_METHOD': 'POST'})