From 158d4c28b224d3c9064df3352e98432e81355c4d Mon Sep 17 00:00:00 2001 From: Tim Burke Date: Mon, 26 Mar 2018 21:49:12 +0000 Subject: [PATCH] swob.Match: remove quotes when checking __contains__ If we're going to drop the quotes during initialization, we should probably drop them when making comparisons, too. Change-Id: I90c6e8a7c6faf8fafb0cd64fabbc9629d6c4c48a --- swift/common/swob.py | 2 ++ test/unit/common/test_swob.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/swift/common/swob.py b/swift/common/swob.py index 9e2e6a1e5a..6acdd1187a 100644 --- a/swift/common/swob.py +++ b/swift/common/swob.py @@ -651,6 +651,8 @@ class Match(object): self.tags.add(tag) def __contains__(self, val): + if val and val.startswith('"') and val.endswith('"'): + val = val[1:-1] return '*' in self.tags or val in self.tags def __repr__(self): diff --git a/test/unit/common/test_swob.py b/test/unit/common/test_swob.py index 9dbe16d777..fed79c860e 100644 --- a/test/unit/common/test_swob.py +++ b/test/unit/common/test_swob.py @@ -270,37 +270,52 @@ class TestMatch(unittest.TestCase): match = swift.common.swob.Match('"a", "b"') self.assertEqual(match.tags, set(('a', 'b'))) self.assertIn('a', match) + self.assertIn('"a"', match) + self.assertNotIn('""a""', match) self.assertIn('b', match) self.assertNotIn('c', match) + self.assertNotIn(None, match) self.assertEqual(repr(match), "Match('a, b')") def test_match_star(self): match = swift.common.swob.Match('"a", "*"') self.assertIn('a', match) + self.assertIn('"a"', match) + self.assertIn('""a""', match) self.assertIn('b', match) self.assertIn('c', match) + self.assertIn(None, match) self.assertEqual(repr(match), "Match('*, a')") def test_match_noquote(self): match = swift.common.swob.Match('a, b') self.assertEqual(match.tags, set(('a', 'b'))) self.assertIn('a', match) + self.assertIn('"a"', match) + self.assertNotIn('""a""', match) self.assertIn('b', match) self.assertNotIn('c', match) + self.assertNotIn(None, 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('"a"', match) + self.assertNotIn('""a""', match) self.assertIn('b', match) self.assertNotIn('c', match) + self.assertNotIn(None, 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('"a"', match) + self.assertNotIn('""a""', match) self.assertIn('b', match) self.assertNotIn('c', match) + self.assertNotIn(None, match) class TestTransferEncoding(unittest.TestCase):