Skip to content

Commit 6743e4d

Browse files
committed
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
1 parent 871f552 commit 6743e4d

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

swift/common/swob.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ def blank(cls, path, environ=None, headers=None, body=None):
703703
'REQUEST_METHOD': 'GET',
704704
'SCRIPT_NAME': '',
705705
'QUERY_STRING': query_string,
706-
'PATH_INFO': path_info,
706+
'PATH_INFO': urllib2.unquote(path_info),
707707
'SERVER_NAME': 'localhost',
708708
'SERVER_PORT': '80',
709709
'HTTP_HOST': 'localhost:80',
@@ -749,7 +749,7 @@ def path_qs(self):
749749
def path(self):
750750
"Provides the full path of the request, excluding the QUERY_STRING"
751751
return urllib2.quote(self.environ.get('SCRIPT_NAME', '') +
752-
self.environ['PATH_INFO'].split('?')[0])
752+
self.environ['PATH_INFO'])
753753

754754
def path_info_pop(self):
755755
"""

test/unit/common/test_swob.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,13 @@ def test_path(self):
290290
'/', environ={'SCRIPT_NAME': '/hi', 'PATH_INFO': '/there'})
291291
self.assertEquals(req.path, '/hi/there')
292292

293+
def test_path_question_mark(self):
294+
req = swift.common.swob.Request.blank('/test%3Ffile')
295+
# This tests that .blank unquotes the path when setting PATH_INFO
296+
self.assertEquals(req.environ['PATH_INFO'], '/test?file')
297+
# This tests that .path requotes it
298+
self.assertEquals(req.path, '/test%3Ffile')
299+
293300
def test_path_info_pop(self):
294301
req = swift.common.swob.Request.blank('/hi/there')
295302
self.assertEquals(req.path_info_pop(), 'hi')

0 commit comments

Comments
 (0)