diff --git a/swift/common/swob.py b/swift/common/swob.py index 9b4842d63d..88da97ddf2 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -622,7 +622,10 @@ class Match(object): """ def __init__(self, headerval): self.tags = set() - for tag in headerval.split(', '): + for tag in headerval.split(','): + tag = tag.strip() + if not tag: + continue if tag.startswith('"') and tag.endswith('"'): self.tags.add(tag[1:-1]) else: diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index 81b8eb4c63..d8fd5da7a0 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -285,6 +285,20 @@ class TestMatch(unittest.TestCase): self.assertIn('b', match) self.assertNotIn('c', match) + def test_match_no_optional_white_space(self): + match = swift.common.swob.Match('"a","b"') + self.assertEqual(match.tags, set(('a', 'b'))) + self.assertIn('a', match) + self.assertIn('b', match) + self.assertNotIn('c', match) + + def test_match_lots_of_optional_white_space(self): + match = swift.common.swob.Match('"a" , , "b" ') + self.assertEqual(match.tags, set(('a', 'b'))) + self.assertIn('a', match) + self.assertIn('b', match) + self.assertNotIn('c', match) + class TestTransferEncoding(unittest.TestCase): def test_is_chunked(self):