Commit 9e72b16b authored by Jelte Jansen's avatar Jelte Jansen

[trac714] allow non-strict json decoding

i.e. allow control-chars in strings
parent 7e41b9c3
......@@ -35,7 +35,7 @@ def from_wire(data):
Raises an AttributeError if the given object has no decode()
method (which should return a string).
'''
return json.loads(data.decode('utf8'))
return json.loads(data.decode('utf8'), strict=False)
if __name__ == "__main__":
import doctest
......
......@@ -31,6 +31,10 @@ class MessageTest(unittest.TestCase):
self.msg2_str = "{\"aaa\": [1, 1.1, true, false, null]}";
self.msg2_wire = self.msg2_str.encode()
self.msg3 = { "aaa": [ 1, 1.1, True, False, "string\n" ] }
self.msg3_str = "{\"aaa\": [1, 1.1, true, false, \"string\n\" ]}";
self.msg3_wire = self.msg3_str.encode()
def test_encode_json(self):
self.assertEqual(self.msg1_wire, isc.cc.message.to_wire(self.msg1))
self.assertEqual(self.msg2_wire, isc.cc.message.to_wire(self.msg2))
......@@ -40,6 +44,7 @@ class MessageTest(unittest.TestCase):
def test_decode_json(self):
self.assertEqual(self.msg1, isc.cc.message.from_wire(self.msg1_wire))
self.assertEqual(self.msg2, isc.cc.message.from_wire(self.msg2_wire))
self.assertEqual(self.msg3, isc.cc.message.from_wire(self.msg3_wire))
self.assertRaises(AttributeError, isc.cc.message.from_wire, 1)
self.assertRaises(ValueError, isc.cc.message.from_wire, b'\x001')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment