summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAsk Solem <ask@rabbitmq.com>2012-06-21 16:42:29 +0100
committerAsk Solem <ask@rabbitmq.com>2012-06-21 16:42:29 +0100
commitc32edef91e221265428a08dd46263421e302eb96 (patch)
tree804a96e02651c8edfe45e15ab2bcbea5823baea6
parentc344fe5dcaeb1d8e1ad4ab4dca08457bc1f7b55c (diff)
downloadanyjson-c32edef91e221265428a08dd46263421e302eb96.tar.gz
Seems like json can't load StringIO to a unicode string
-rw-r--r--anyjson/__init__.py2
-rw-r--r--tests/test_implementations.py9
2 files changed, 10 insertions, 1 deletions
diff --git a/anyjson/__init__.py b/anyjson/__init__.py
index f254a42..0aee329 100644
--- a/anyjson/__init__.py
+++ b/anyjson/__init__.py
@@ -94,7 +94,7 @@ class _JsonImplementation(object):
ValueError if the string could not be parsed."""
# uses StringIO to support buffer objects.
try:
- if self._filedecode:
+ if self._filedecode and not isinstance(s, basestring):
return self._filedecode(StringIO(s))
return self._decode(s)
except self._decode_error, exc:
diff --git a/tests/test_implementations.py b/tests/test_implementations.py
index a884459..c6f0df2 100644
--- a/tests/test_implementations.py
+++ b/tests/test_implementations.py
@@ -46,3 +46,12 @@ def test_exceptions():
assert_raises(TypeError, anyjson.serialize, [object()])
assert_raises(ValueError, anyjson.loads, "[")
assert_raises(ValueError, anyjson.deserialize, "[")
+
+
+def test_json_loads_unicode():
+ try:
+ anyjson.force_implementation("json")
+ except ImportError:
+ return
+
+ assert "foo" in anyjson.loads(u'{"foo": "bar"}')