diff --git a/swift/common/swob.py b/swift/common/swob.py index 026632033c..df94233360 100755 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -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] diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index 7c85f9c64a..44c41c98b8 100755 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -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'})