Author: Antonio Cuni <[email protected]>
Branch: fastjson
Changeset: r64978:bb292772f94a
Date: 2013-06-25 18:01 +0200
http://bitbucket.org/pypy/pypy/changeset/bb292772f94a/
Log: accept only bytestrings, not unicode
diff --git a/pypy/module/_fastjson/interp_decoder.py
b/pypy/module/_fastjson/interp_decoder.py
--- a/pypy/module/_fastjson/interp_decoder.py
+++ b/pypy/module/_fastjson/interp_decoder.py
@@ -322,8 +322,11 @@
return i
-@unwrap_spec(s=str)
-def loads(space, s):
+def loads(space, w_s):
+ if space.isinstance_w(w_s, space.w_unicode):
+ raise OperationError(space.w_TypeError,
+ space.wrap("Expected utf8-encoded str, got
unicode"))
+ s = space.str_w(w_s)
decoder = JSONDecoder(space, s)
w_res = decoder.decode_any(0)
i = decoder.skip_whitespace(decoder.pos)
diff --git a/pypy/module/_fastjson/test/test__fastjson.py
b/pypy/module/_fastjson/test/test__fastjson.py
--- a/pypy/module/_fastjson/test/test__fastjson.py
+++ b/pypy/module/_fastjson/test/test__fastjson.py
@@ -15,6 +15,11 @@
class AppTest(object):
spaceconfig = {"objspace.usemodules._fastjson": True}
+ def test_raise_on_unicode(self):
+ import _fastjson
+ raises(TypeError, _fastjson.loads, u"42")
+
+
def test_decode_constants(self):
import _fastjson
assert _fastjson.loads('null') is None
@@ -143,3 +148,4 @@
assert _fastjson.loads('[1, 2]') == [1, 2]
raises(ValueError, "_fastjson.loads('[1: 2]')")
raises(ValueError, "_fastjson.loads('[1, 2')")
+
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit