check for error conditions in _json #3623
This commit is contained in:
parent
eaede315d1
commit
595e3cbb3d
|
@ -2,6 +2,7 @@ import sys
|
||||||
import decimal
|
import decimal
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
|
import json
|
||||||
import json.decoder
|
import json.decoder
|
||||||
|
|
||||||
class TestScanString(TestCase):
|
class TestScanString(TestCase):
|
||||||
|
@ -100,3 +101,9 @@ class TestScanString(TestCase):
|
||||||
self.assertEquals(
|
self.assertEquals(
|
||||||
scanstring('["Bad value", truth]', 2, None, True),
|
scanstring('["Bad value", truth]', 2, None, True),
|
||||||
(u'Bad value', 12))
|
(u'Bad value', 12))
|
||||||
|
|
||||||
|
def test_issue3623(self):
|
||||||
|
self.assertRaises(ValueError, json.decoder.scanstring, b"xxx", 1,
|
||||||
|
"xxx")
|
||||||
|
self.assertRaises(UnicodeDecodeError,
|
||||||
|
json.encoder.encode_basestring_ascii, b"xx\xff")
|
||||||
|
|
|
@ -179,11 +179,13 @@ raise_errmsg(char *msg, PyObject *s, Py_ssize_t end)
|
||||||
errmsg_fn = PyObject_GetAttrString(decoder, "errmsg");
|
errmsg_fn = PyObject_GetAttrString(decoder, "errmsg");
|
||||||
if (errmsg_fn == NULL)
|
if (errmsg_fn == NULL)
|
||||||
return;
|
return;
|
||||||
Py_XDECREF(decoder);
|
Py_DECREF(decoder);
|
||||||
}
|
}
|
||||||
pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
|
pymsg = PyObject_CallFunction(errmsg_fn, "(zOn)", msg, s, end);
|
||||||
PyErr_SetObject(PyExc_ValueError, pymsg);
|
if (pymsg) {
|
||||||
Py_DECREF(pymsg);
|
PyErr_SetObject(PyExc_ValueError, pymsg);
|
||||||
|
Py_DECREF(pymsg);
|
||||||
|
}
|
||||||
/*
|
/*
|
||||||
|
|
||||||
def linecol(doc, pos):
|
def linecol(doc, pos):
|
||||||
|
|
Loading…
Reference in New Issue