summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2011-09-03 18:48:28 -0700
committerBob Ippolito <bob@redivi.com>2011-09-03 18:48:28 -0700
commit308b7421566889b10766cdab144874e29b38ff99 (patch)
tree0a53dd68e51861b6b5de5039f3560a5013ffb477
parent63786a180ecff31398055c456e3aa543ff79c9af (diff)
parentfb1a518e536e6bce349cd776a90a03895fa7f61b (diff)
downloadsimplejson-308b7421566889b10766cdab144874e29b38ff99.tar.gz
Merge branch 'scan-ValueError-gh15'
-rw-r--r--.gitignore2
-rw-r--r--CHANGES.txt3
-rw-r--r--simplejson/_speedups.c10
-rw-r--r--simplejson/tests/test_errors.py13
4 files changed, 26 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index bf76e93..f2b563c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,8 @@
*.egg
*.pyc
*.so
+/.coverage
+/coverage.xml
/build
/dist
/docs
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 c8b836a..620ccf3 100644
--- a/simplejson/tests/test_errors.py
+++ b/simplejson/tests/test_errors.py
@@ -19,3 +19,16 @@ class TestErrors(TestCase):
self.assertEquals(err.colno, 1)
self.assertEquals(err.endlineno, 3)
self.assertEquals(err.endcolno, 2)
+
+ def test_scan_error(self):
+ err = None
+ 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