summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2015-04-16 17:00:19 -0400
committerScott Moser <smoser@ubuntu.com>2015-04-16 17:00:19 -0400
commit341a805fca9a06ce12e9f4bbbe15b3dded9eb6a4 (patch)
tree71fce1c6c426f75c7126522a3a6efb57e4a9b26e /cloudinit/util.py
parentdcd4b2b371059bd6249b4e43af371ee1162273e8 (diff)
downloadvyos-cloud-init-341a805fca9a06ce12e9f4bbbe15b3dded9eb6a4.tar.gz
vyos-cloud-init-341a805fca9a06ce12e9f4bbbe15b3dded9eb6a4.zip
fix cloud-config-archive handling
handling of cloud-config-archive input would fail in fully_decoded_payload. part.get_charset() would return a Charset object, but get_charset.input_codec is a string suitable for passing to decode. This handles that correctly, and is more careful about binary data inside input. The test added verifies that cloud-config inside a cloud-config-archive is handled correctly and also that binary data there is ignored without exceptions raised. LP: #1445143
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 971c1c2d..cae57770 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -121,8 +121,12 @@ def fully_decoded_payload(part):
if (six.PY3 and
part.get_content_maintype() == 'text' and
isinstance(cte_payload, bytes)):
- charset = part.get_charset() or 'utf-8'
- return cte_payload.decode(charset, errors='surrogateescape')
+ charset = part.get_charset()
+ if charset and charset.input_codec:
+ encoding = charset.input_codec
+ else:
+ encoding = 'utf-8'
+ return cte_payload.decode(encoding, errors='surrogateescape')
return cte_payload