Fix bug with swob.Request.path_info_pop

path_info_pop didn't behave as the webob one did with single segment
paths like /one and with root-only paths /

Now it should.

Change-Id: Ib88344de386ab9e8975e7f48c1afc47731992ee2
This commit is contained in:
gholt 2012-11-28 00:08:26 +00:00
parent 2ad23a25e8
commit 4063123e3c
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'})