diff options
| author | Chmouel Boudjnah <chmouel@enovance.com> | 2013-11-29 22:59:27 +0100 |
|---|---|---|
| committer | Chmouel Boudjnah <chmouel@enovance.com> | 2013-12-06 13:28:01 +0100 |
| commit | 983988093f3848671cb27b3c1956e4ca62087dff (patch) | |
| tree | bd77fb1360d85c554ee3aa3176d48039601d6b6a | |
| parent | 0ef054585a93f80ba4bc72f953f832372e65db60 (diff) | |
| download | python-swiftclient-983988093f3848671cb27b3c1956e4ca62087dff.tar.gz | |
Don't crash when header is value of None
Before commit 7d88d14d (http://git.io/hhJWdQ) swifclient used to accept
header value with the type None :
{'Headers': None}
It would just be happy with it with those None headers and not process
them, reinstate the old behavior.
Closes-Bug: 1256441
Change-Id: Ic7f80c38ef2ce9ef1687ed0d6d65521f2e754905
| -rw-r--r-- | swiftclient/client.py | 4 | ||||
| -rw-r--r-- | tests/test_swiftclient.py | 5 |
2 files changed, 8 insertions, 1 deletions
diff --git a/swiftclient/client.py b/swiftclient/client.py index 8dc4b71..d7349f3 100644 --- a/swiftclient/client.py +++ b/swiftclient/client.py @@ -97,7 +97,9 @@ def quote(value, safe='/'): def validate_headers(headers): if headers: - for key, value in headers.iteritems(): + for key, raw_value in headers.iteritems(): + value = str(encode_utf8(raw_value)) + if '\n' in value: raise InvalidHeadersException("%r header contained a " "newline" % key) diff --git a/tests/test_swiftclient.py b/tests/test_swiftclient.py index 1c6d3e9..7d58938 100644 --- a/tests/test_swiftclient.py +++ b/tests/test_swiftclient.py @@ -190,6 +190,11 @@ class TestHttpHelpers(MockHttpTest): self.assertRaises(c.InvalidHeadersException, c.validate_headers, headers) + def test_validate_headers_with_other_than_str(self): + for t in (None, 1, 1.0, 1L, u"A"): + self.assertEqual(c.validate_headers({'key': t}), + None) + # TODO: following tests are placeholders, need more tests, better coverage |
