summaryrefslogtreecommitdiff
path: root/simplejson/tests
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-05-21 13:28:24 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2017-05-21 15:16:56 +0300
commit9cef9f5951eabaf010fc0b8d08b2d6e0c7dcf526 (patch)
treeb3ac0bbc5f8433a1edfa6ec4a6944d69d7167d62 /simplejson/tests
parente84076f2cac4dd3cc98ed947316928cb5ba7c9b2 (diff)
downloadsimplejson-9cef9f5951eabaf010fc0b8d08b2d6e0c7dcf526.tar.gz
Fix a crash wish unencodable encoding in the encoder.unencodable-encoder-encoding
JSONEncoder.encode() crashed in Python 3 when encoded bytes keys if the encoding was not encodable to utf-8 (contained surrogates).
Diffstat (limited to 'simplejson/tests')
-rw-r--r--simplejson/tests/test_speedups.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/simplejson/tests/test_speedups.py b/simplejson/tests/test_speedups.py
index 89a30d9..b59eeca 100644
--- a/simplejson/tests/test_speedups.py
+++ b/simplejson/tests/test_speedups.py
@@ -1,10 +1,12 @@
+from __future__ import with_statement
+
import sys
import unittest
from unittest import TestCase
import simplejson
from simplejson import encoder, decoder, scanner
-from simplejson.compat import PY3, long_type
+from simplejson.compat import PY3, long_type, b
def has_speedups():
@@ -80,3 +82,9 @@ class TestEncode(TestCase):
def test():
encoder.JSONEncoder(int_as_string_bitcount=long_count).encode(0)
self.assertRaises((TypeError, OverflowError), test)
+
+ if PY3:
+ @skip_if_speedups_missing
+ def test_bad_encoding(self):
+ with self.assertRaises(UnicodeEncodeError):
+ encoder.JSONEncoder(encoding='\udcff').encode({b('key'): 123})