summaryrefslogtreecommitdiff
path: root/simplejson/tests
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-03-29 00:17:55 +0100
committerRichard van der Hoff <richard@matrix.org>2018-03-29 00:17:55 +0100
commit19012377f349da419f80e91ecd41d5f09f90d32b (patch)
treefaa09ee0557ef874d70e96d83d1de68976765e8e /simplejson/tests
parent0406430cbcb0e31d27bd064db57837b94ed05294 (diff)
downloadsimplejson-19012377f349da419f80e91ecd41d5f09f90d32b.tar.gz
Avoid escaping U+2028 and U+2029 without ensure_ascii
There is no need to escape U+2028 and U+2029 when ensure_ascii is false, and doing so makes us inconsistent with the standard JSON library.
Diffstat (limited to 'simplejson/tests')
-rw-r--r--simplejson/tests/test_encode_for_html.py8
-rw-r--r--simplejson/tests/test_unicode.py5
2 files changed, 11 insertions, 2 deletions
diff --git a/simplejson/tests/test_encode_for_html.py b/simplejson/tests/test_encode_for_html.py
index f995254..3a840aa 100644
--- a/simplejson/tests/test_encode_for_html.py
+++ b/simplejson/tests/test_encode_for_html.py
@@ -7,11 +7,19 @@ class TestEncodeForHTML(unittest.TestCase):
def setUp(self):
self.decoder = json.JSONDecoder()
self.encoder = json.JSONEncoderForHTML()
+ self.non_ascii_encoder = json.JSONEncoderForHTML(ensure_ascii=False)
def test_basic_encode(self):
self.assertEqual(r'"\u0026"', self.encoder.encode('&'))
self.assertEqual(r'"\u003c"', self.encoder.encode('<'))
self.assertEqual(r'"\u003e"', self.encoder.encode('>'))
+ self.assertEqual(r'"\u2028"', self.encoder.encode(u'\u2028'))
+
+ def test_non_ascii_basic_encode(self):
+ self.assertEqual(r'"\u0026"', self.non_ascii_encoder.encode('&'))
+ self.assertEqual(r'"\u003c"', self.non_ascii_encoder.encode('<'))
+ self.assertEqual(r'"\u003e"', self.non_ascii_encoder.encode('>'))
+ self.assertEqual(r'"\u2028"', self.non_ascii_encoder.encode(u'\u2028'))
def test_basic_roundtrip(self):
for char in '&<>':
diff --git a/simplejson/tests/test_unicode.py b/simplejson/tests/test_unicode.py
index 3b37f65..1c7e95e 100644
--- a/simplejson/tests/test_unicode.py
+++ b/simplejson/tests/test_unicode.py
@@ -106,10 +106,11 @@ class TestUnicode(TestCase):
s1 = u'\u2029\u2028'
s2 = s1.encode('utf8')
expect = '"\\u2029\\u2028"'
+ expect_non_ascii = u'"\u2029\u2028"'
self.assertEqual(json.dumps(s1), expect)
self.assertEqual(json.dumps(s2), expect)
- self.assertEqual(json.dumps(s1, ensure_ascii=False), expect)
- self.assertEqual(json.dumps(s2, ensure_ascii=False), expect)
+ self.assertEqual(json.dumps(s1, ensure_ascii=False), expect_non_ascii)
+ self.assertEqual(json.dumps(s2, ensure_ascii=False), expect_non_ascii)
def test_invalid_escape_sequences(self):
# incomplete escape sequence