[pypy-commit] pypy default: merged default head
plan_rich
pypy.commits at gmail.com
Thu Jul 14 14:51:10 EDT 2016
Author: Richard Plangger <planrichi at gmail.com>
Branch:
Changeset: r85706:0cdc78795c00
Date: 2016-07-14 13:49 -0500
http://bitbucket.org/pypy/pypy/changeset/0cdc78795c00/
Log: merged default head
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
@@ -360,10 +360,11 @@
hexdigits = self.getslice(start, i)
try:
val = int(hexdigits, 16)
- if val & 0xfc00 == 0xd800:
+ if sys.maxunicode > 65535 and 0xd800 <= val <= 0xdfff:
# surrogate pair
- val = self.decode_surrogate_pair(i, val)
- i += 6
+ if self.ll_chars[i] == '\\' and self.ll_chars[i+1] == 'u':
+ val = self.decode_surrogate_pair(i, val)
+ i += 6
except ValueError:
self._raise("Invalid \uXXXX escape (char %d)", i-1)
return # help the annotator to know that we'll never go beyond
@@ -375,8 +376,9 @@
return i
def decode_surrogate_pair(self, i, highsurr):
- if self.ll_chars[i] != '\\' or self.ll_chars[i+1] != 'u':
- self._raise("Unpaired high surrogate at char %d", i)
+ """ uppon enter the following must hold:
+ chars[i] == "\\" and chars[i+1] == "u"
+ """
i += 2
hexdigits = self.getslice(i, i+4)
lowsurr = int(hexdigits, 16) # the possible ValueError is caugth by the caller
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
@@ -184,6 +184,12 @@
res = _pypyjson.loads('"z\\ud834\\udd20x"')
assert res == expected
+ def test_surrogate_pair(self):
+ import _pypyjson
+ json = '{"a":"\\uD83D"}'
+ res = _pypyjson.loads(json)
+ assert res == {u'a': u'\ud83d'}
+
def test_tab_in_string_should_fail(self):
import _pypyjson
# http://json.org/JSON_checker/test/fail25.json
More information about the pypy-commit
mailing list