# HG changeset patch # User Bob Ippolito <bob@redivi.com> # Date 1315100786 25200 # Sat Sep 03 18:46:26 2011 -0700 # Node ID a1c439bbb9d882588274a6f74a83e827f9c0c6b4 # Parent e1ff40afda1f35d48044f70d72fea2e450366f6a also test unicode and fix the JSONDecodeError issue diff --git a/CHANGES.txt b/CHANGES.txt --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,5 +1,8 @@ Version 2.1.7 released 2011-XX-XX +* JSONDecodeError is now raised instead of ValueError when a document + ends with an opening quote and the C speedups are in use. + https://github.com/simplejson/simplejson/issues/15 * Updated documentation with information about JSONDecodeError * Force unicode linebreak characters to be escaped (U+2028 and U+2029) http://timelessrepo.com/json-isnt-a-javascript-subset diff --git a/simplejson/_speedups.c b/simplejson/_speedups.c --- a/simplejson/_speedups.c +++ b/simplejson/_speedups.c @@ -483,7 +483,10 @@ PyObject *chunks = NULL; PyObject *chunk = NULL; - if (end < 0 || len <= end) { + if (len == end) { + raise_errmsg("Unterminated string starting at", pystr, begin); + } + else if (end < 0 || len < end) { PyErr_SetString(PyExc_ValueError, "end is out of bounds"); goto bail; } @@ -689,7 +692,10 @@ PyObject *chunks = NULL; PyObject *chunk = NULL; - if (end < 0 || len <= end) { + if (len == end) { + raise_errmsg("Unterminated string starting at", pystr, begin); + } + else if (end < 0 || len < end) { PyErr_SetString(PyExc_ValueError, "end is out of bounds"); goto bail; } diff --git a/simplejson/tests/test_errors.py b/simplejson/tests/test_errors.py --- a/simplejson/tests/test_errors.py +++ b/simplejson/tests/test_errors.py @@ -22,12 +22,13 @@ def test_scan_error(self): err = None - try: - json.loads('{"asdf": "') - except json.JSONDecodeError, e: - err = e - else: - self.fail('Expected JSONDecodeError') - self.assertEquals(err.lineno, 1) - self.assertEquals(err.colno, 9) + for t in (str, unicode): + try: + json.loads(t('{"asdf": "')) + except json.JSONDecodeError, e: + err = e + else: + self.fail('Expected JSONDecodeError') + self.assertEquals(err.lineno, 1) + self.assertEquals(err.colno, 9) \ No newline at end of file