diff options
author | Bob Ippolito <bob@redivi.com> | 2011-09-03 18:46:26 -0700 |
---|---|---|
committer | Bob Ippolito <bob@redivi.com> | 2011-09-03 18:46:26 -0700 |
commit | fb1a518e536e6bce349cd776a90a03895fa7f61b (patch) | |
tree | 0a53dd68e51861b6b5de5039f3560a5013ffb477 | |
parent | 2d765188301e68e47f20e90b81de1476213209f4 (diff) | |
download | simplejson-scan-ValueError-gh15.tar.gz |
also test unicode and fix the JSONDecodeError issuescan-ValueError-gh15
-rw-r--r-- | CHANGES.txt | 3 | ||||
-rw-r--r-- | simplejson/_speedups.c | 10 | ||||
-rw-r--r-- | simplejson/tests/test_errors.py | 17 |
3 files changed, 20 insertions, 10 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index cf8510d..4861628 100644 --- 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 index 8b34747..97821de 100644 --- a/simplejson/_speedups.c +++ b/simplejson/_speedups.c @@ -483,7 +483,10 @@ scanstring_str(PyObject *pystr, Py_ssize_t end, char *encoding, int strict, Py_s 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 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next 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 index e0b958c..620ccf3 100644 --- a/simplejson/tests/test_errors.py +++ b/simplejson/tests/test_errors.py @@ -22,12 +22,13 @@ class TestErrors(TestCase): 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 |