From e7c8c578d9e5b0aa7e56b02bd9c39baa99d2d6ae Mon Sep 17 00:00:00 2001 From: Michael MATUR Date: Mon, 25 May 2015 15:13:01 +0200 Subject: [PATCH] fixup!Patch of "parse_content_disposition" method to meet RFC2183 The spec of Content-Disposition does not require a space character after comma: http://www.ietf.org/rfc/rfc2183.txt Change-Id: Iff438dc36ce78c6a79bb66ab3d889a8dae7c0e1f Closes-Bug: #1458497 --- swift/common/utils.py | 4 ++-- test/unit/common/test_utils.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/swift/common/utils.py b/swift/common/utils.py index 19dcfd3d61..11a97d126b 100644 --- a/swift/common/utils.py +++ b/swift/common/utils.py @@ -3355,8 +3355,8 @@ def parse_content_disposition(header): """ attributes = {} attrs = '' - if '; ' in header: - header, attrs = header.split('; ', 1) + if ';' in header: + header, attrs = [x.strip() for x in header.split(';', 1)] m = True while m: m = ATTRIBUTES_RE.match(attrs) diff --git a/test/unit/common/test_utils.py b/test/unit/common/test_utils.py index 48610c1a7b..113b712ab1 100644 --- a/test/unit/common/test_utils.py +++ b/test/unit/common/test_utils.py @@ -4629,6 +4629,12 @@ class TestParseContentDisposition(unittest.TestCase): self.assertEquals(name, 'form-data') self.assertEquals(attrs, {'name': 'somefile', 'filename': 'test.html'}) + def test_content_disposition_without_white_space(self): + name, attrs = utils.parse_content_disposition( + 'form-data;name="somefile";filename="test.html"') + self.assertEquals(name, 'form-data') + self.assertEquals(attrs, {'name': 'somefile', 'filename': 'test.html'}) + class TestIterMultipartMimeDocuments(unittest.TestCase):