[pypy-commit] pypy py3k: Allow lone surrogates in _pypyjson

rlamy pypy.commits at gmail.com
Fri Aug 19 11:19:25 EDT 2016


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3k
Changeset: r86321:a4b31c94bd5c
Date: 2016-08-19 16:18 +0100
http://bitbucket.org/pypy/pypy/changeset/a4b31c94bd5c/

Log:	Allow lone surrogates in _pypyjson

diff --git a/pypy/module/_pypyjson/interp_decoder.py b/pypy/module/_pypyjson/interp_decoder.py
--- a/pypy/module/_pypyjson/interp_decoder.py
+++ b/pypy/module/_pypyjson/interp_decoder.py
@@ -327,7 +327,8 @@
             i += 1
             if ch == '"':
                 content_utf8 = builder.build()
-                content_unicode = unicodehelper.decode_utf8(self.space, content_utf8)
+                content_unicode = unicodehelper.decode_utf8(
+                    self.space, content_utf8, allow_surrogates=True)
                 self.last_type = TYPE_STRING
                 self.pos = i
                 return self.space.wrap(content_unicode)
@@ -374,7 +375,8 @@
                    # this point
         #
         uchr = runicode.code_to_unichr(val)     # may be a surrogate pair again
-        utf8_ch = unicodehelper.encode_utf8(self.space, uchr)
+        utf8_ch = unicodehelper.encode_utf8(
+            self.space, uchr, allow_surrogates=True)
         builder.append(utf8_ch)
         return i
 
diff --git a/pypy/module/_pypyjson/test/test__pypyjson.py b/pypy/module/_pypyjson/test/test__pypyjson.py
--- a/pypy/module/_pypyjson/test/test__pypyjson.py
+++ b/pypy/module/_pypyjson/test/test__pypyjson.py
@@ -10,10 +10,10 @@
     assert dec.skip_whitespace(8) == len(s)
     dec.close()
 
-    
+
 
 class AppTest(object):
-    spaceconfig = {"objspace.usemodules._pypyjson": True}
+    spaceconfig = {"usemodules": ['_pypyjson']}
 
     def test_raise_on_bytes(self):
         import _pypyjson
@@ -40,7 +40,7 @@
         raises(ValueError, _pypyjson.loads, 'fa')
         raises(ValueError, _pypyjson.loads, 'f')
         raises(ValueError, _pypyjson.loads, 'falXX')
-        
+
 
     def test_decode_string(self):
         import _pypyjson
@@ -69,7 +69,7 @@
         import _pypyjson
         assert _pypyjson.loads(r'"\\"') == '\\'
         assert _pypyjson.loads(r'"\""') == '"'
-        assert _pypyjson.loads(r'"\/"') == '/'       
+        assert _pypyjson.loads(r'"\/"') == '/'
         assert _pypyjson.loads(r'"\b"') == '\b'
         assert _pypyjson.loads(r'"\f"') == '\f'
         assert _pypyjson.loads(r'"\n"') == '\n'
@@ -85,7 +85,7 @@
         import _pypyjson
         s = r'"hello\nworld' # missing the trailing "
         raises(ValueError, "_pypyjson.loads(s)")
-        
+
     def test_escape_sequence_unicode(self):
         import _pypyjson
         s = r'"\u1234"'
@@ -166,7 +166,7 @@
     def test_decode_object_nonstring_key(self):
         import _pypyjson
         raises(ValueError, "_pypyjson.loads('{42: 43}')")
-        
+
     def test_decode_array(self):
         import _pypyjson
         assert _pypyjson.loads('[]') == []
@@ -183,7 +183,7 @@
         res = _pypyjson.loads('"z\\ud834\\udd20x"')
         assert res == expected
 
-    def test_surrogate_pair(self):
+    def test_lone_surrogate(self):
         import _pypyjson
         json = '{"a":"\\uD83D"}'
         res = _pypyjson.loads(json)


More information about the pypy-commit mailing list