From: Jelte Jansen Date: Thu, 30 Jun 2011 09:51:13 +0000 (+0200) Subject: [trac714] allow non-strict json decoding X-Git-Tag: perftcpdns_before_epoll~231^2~25^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=9e72b16bcbfcdc819cbdc437feb10f73b1694107;p=thirdparty%2Fkea.git [trac714] allow non-strict json decoding i.e. allow control-chars in strings --- diff --git a/src/lib/python/isc/cc/message.py b/src/lib/python/isc/cc/message.py index 3601c41f5e..3ebcc438c8 100644 --- a/src/lib/python/isc/cc/message.py +++ b/src/lib/python/isc/cc/message.py @@ -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 diff --git a/src/lib/python/isc/cc/tests/message_test.py b/src/lib/python/isc/cc/tests/message_test.py index 20242018e4..c417068120 100644 --- a/src/lib/python/isc/cc/tests/message_test.py +++ b/src/lib/python/isc/cc/tests/message_test.py @@ -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')