summaryrefslogtreecommitdiff
path: root/simplejson
diff options
context:
space:
mode:
Diffstat (limited to 'simplejson')
-rw-r--r--simplejson/_speedups.c10
-rw-r--r--simplejson/tests/test_errors.py17
2 files changed, 17 insertions, 10 deletions
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