Swob bugfixes; for ? in names specifically

It was discovered that uploading items with ? in their names (encoded
with %3F of course) made Swob fail in that it trimmed off everything
after the ? as if it were a query string.

Change-Id: Ie686db9a2177aafad2e77c307ffc3f446646fbb5
This commit is contained in:
gholt 2012-11-30 21:31:21 +00:00
parent 871f552ab6
commit 6743e4d57f
2 changed files with 9 additions and 2 deletions

View File

@ -703,7 +703,7 @@ class Request(object):
'REQUEST_METHOD': 'GET',
'SCRIPT_NAME': '',
'QUERY_STRING': query_string,
'PATH_INFO': path_info,
'PATH_INFO': urllib2.unquote(path_info),
'SERVER_NAME': 'localhost',
'SERVER_PORT': '80',
'HTTP_HOST': 'localhost:80',
@ -749,7 +749,7 @@ class Request(object):
def path(self):
"Provides the full path of the request, excluding the QUERY_STRING"
return urllib2.quote(self.environ.get('SCRIPT_NAME', '') +
self.environ['PATH_INFO'].split('?')[0])
self.environ['PATH_INFO'])
def path_info_pop(self):
"""

View File

@ -290,6 +290,13 @@ class TestRequest(unittest.TestCase):
'/', environ={'SCRIPT_NAME': '/hi', 'PATH_INFO': '/there'})
self.assertEquals(req.path, '/hi/there')
def test_path_question_mark(self):
req = swift.common.swob.Request.blank('/test%3Ffile')
# This tests that .blank unquotes the path when setting PATH_INFO
self.assertEquals(req.environ['PATH_INFO'], '/test?file')
# This tests that .path requotes it
self.assertEquals(req.path, '/test%3Ffile')
def test_path_info_pop(self):
req = swift.common.swob.Request.blank('/hi/there')
self.assertEquals(req.path_info_pop(), 'hi')