Merge "swob.Match: Optional whitespace is optional"

This commit is contained in:
Zuul 2018-04-10 08:13:39 +00:00 committed by Gerrit Code Review
commit bbf5e5c7f3
2 changed files with 18 additions and 1 deletions

View File

@ -623,6 +623,9 @@ class Match(object):
def __init__(self, headerval):
self.tags = set()
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:

View File

@ -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):