Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71427ee

Browse files
committed
Merge Python 3.5.0b4 changes back with 3.5 branch head.
2 parents 3d1dc90 + f002225 commit 71427ee

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

Lib/test/test_json/test_separators.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ def test_separators(self):
3939
self.assertEqual(h2, h)
4040
self.assertEqual(d2, expect)
4141

42+
def test_illegal_separators(self):
43+
h = {1: 2, 3: 4}
44+
self.assertRaises(TypeError, self.dumps, h, separators=(b', ', ': '))
45+
self.assertRaises(TypeError, self.dumps, h, separators=(', ', b': '))
46+
self.assertRaises(TypeError, self.dumps, h, separators=(b', ', b': '))
47+
4248

4349
class TestPySeparators(TestSeparators, PyTest): pass
4450
class TestCSeparators(TestSeparators, CTest): pass

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Core and Builtins
4040
Library
4141
-------
4242

43+
- Issue #24683: Fixed crashes in _json functions called with arguments of
44+
inappropriate type.
45+
4346
- Issue #21697: shutil.copytree() now correctly handles symbolic links that
4447
point to directories. Patch by Eduardo Seabra and Thomas Kluyver.
4548

Modules/_json.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,11 +1344,19 @@ encoder_init(PyObject *self, PyObject *args, PyObject *kwds)
13441344
assert(PyEncoder_Check(self));
13451345
s = (PyEncoderObject *)self;
13461346

1347-
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOOOOOp:make_encoder", kwlist,
1348-
&markers, &defaultfn, &encoder, &indent, &key_separator, &item_separator,
1347+
if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOOOUUOOp:make_encoder", kwlist,
1348+
&markers, &defaultfn, &encoder, &indent,
1349+
&key_separator, &item_separator,
13491350
&sort_keys, &skipkeys, &allow_nan))
13501351
return -1;
13511352

1353+
if (markers != Py_None && !PyDict_Check(markers)) {
1354+
PyErr_Format(PyExc_TypeError,
1355+
"make_encoder() argument 1 must be dict or None, "
1356+
"not %.200s", Py_TYPE(markers)->tp_name);
1357+
return -1;
1358+
}
1359+
13521360
s->markers = markers;
13531361
s->defaultfn = defaultfn;
13541362
s->encoder = encoder;

0 commit comments

Comments
 (0)