Skip to content

Commit

Permalink
Swob bugfixes; for ? in names specifically
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gholt committed Nov 30, 2012
1 parent 871f552 commit 6743e4d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions swift/common/swob.py
Expand Up @@ -703,7 +703,7 @@ def blank(cls, path, environ=None, headers=None, body=None):
'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',
Expand Down Expand Up @@ -749,7 +749,7 @@ def path_qs(self):
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):
"""
Expand Down
7 changes: 7 additions & 0 deletions test/unit/common/test_swob.py
Expand Up @@ -290,6 +290,13 @@ def test_path(self):
'/', 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')
Expand Down

0 comments on commit 6743e4d

Please sign in to comment.