Skip to content
Snippets Groups Projects
Commit 6bc2f946c337 authored by Bob Ippolito's avatar Bob Ippolito
Browse files

Merge branch 'sporty-master'

No related branches found
No related tags found
No related merge requests found
Version 3.6.0 released 2014-07-21
* Automatically strip any UTF-8 BOM from input to more closely
follow the latest specs
https://github.com/simplejson/simplejson/pull/101
Version 3.5.3 released 2014-06-24
* Fix lower bound checking in scan_once / raw_decode API
......
......@@ -42,5 +42,5 @@
# other places throughout the built documents.
#
# The short X.Y version.
version = '3.5'
version = '3.6'
# The full version, including alpha/beta/rc tags.
......@@ -46,5 +46,5 @@
# The full version, including alpha/beta/rc tags.
release = '3.5.3'
release = '3.6.0'
# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
......
......@@ -98,7 +98,7 @@
Expecting property name: line 1 column 3 (char 2)
"""
from __future__ import absolute_import
__version__ = '3.5.3'
__version__ = '3.6.0'
__all__ = [
'dump', 'dumps', 'load', 'loads',
'JSONDecoder', 'JSONDecodeError', 'JSONEncoder',
......
......@@ -390,4 +390,11 @@
raise JSONDecodeError('Expecting value', s, idx)
if _PY3 and not isinstance(s, text_type):
raise TypeError("Input string must be text, not bytes")
# strip UTF-8 bom
if len(s) > idx:
ord0 = ord(s[idx])
if ord0 == 0xfeff:
idx += 1
elif ord0 == 0xef and s[idx:idx + 3] == '\xef\xbb\xbf':
idx += 3
return self.scan_once(s, idx=_w(s, idx).end())
import sys
import codecs
from unittest import TestCase
import simplejson as json
......@@ -2,7 +3,7 @@
from unittest import TestCase
import simplejson as json
from simplejson.compat import unichr, text_type, b, u
from simplejson.compat import unichr, text_type, b, u, BytesIO
class TestUnicode(TestCase):
def test_encoding1(self):
......@@ -143,3 +144,10 @@
self.assertEqual(
json.dumps(c, ensure_ascii=False),
'"' + c + '"')
def test_strip_bom(self):
content = u"\u3053\u3093\u306b\u3061\u308f"
json_doc = codecs.BOM_UTF8 + b(json.dumps(content))
self.assertEqual(json.load(BytesIO(json_doc)), content)
for doc in json_doc, json_doc.decode('utf8'):
self.assertEqual(json.loads(doc), content)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment