From 983988093f3848671cb27b3c1956e4ca62087dff Mon Sep 17 00:00:00 2001 From: Chmouel Boudjnah Date: Fri, 29 Nov 2013 22:59:27 +0100 Subject: [PATCH] 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 --- swiftclient/client.py | 4 +++- tests/test_swiftclient.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/swiftclient/client.py b/swiftclient/client.py index 8dc4b716..d7349f33 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 1c6d3e96..7d589382 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