PYTHON-2631 Add missing error message to InvalidBSON error (#589)
This commit is contained in:
parent
c0321ef2c5
commit
cc029a1e62
@ -2342,7 +2342,7 @@ static int _element_to_dict(PyObject* self, const char* string,
|
||||
if (name_length > BSON_MAX_SIZE || position + name_length >= max) {
|
||||
PyObject* InvalidBSON = _error("InvalidBSON");
|
||||
if (InvalidBSON) {
|
||||
PyErr_SetNone(InvalidBSON);
|
||||
PyErr_SetString(InvalidBSON, "field name too large");
|
||||
Py_DECREF(InvalidBSON);
|
||||
}
|
||||
return -1;
|
||||
|
||||
@ -367,6 +367,13 @@ class TestBSON(unittest.TestCase):
|
||||
with self.assertRaises(InvalidBSON, msg=msg):
|
||||
list(decode_file_iter(scratch))
|
||||
|
||||
def test_invalid_field_name(self):
|
||||
# Decode a truncated field
|
||||
with self.assertRaises(InvalidBSON) as ctx:
|
||||
decode(b'\x0b\x00\x00\x00\x02field\x00')
|
||||
# Assert that the InvalidBSON error message is not empty.
|
||||
self.assertTrue(str(ctx.exception))
|
||||
|
||||
def test_data_timestamp(self):
|
||||
self.assertEqual({"test": Timestamp(4, 20)},
|
||||
decode(b"\x13\x00\x00\x00\x11\x74\x65\x73\x74\x00\x14"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user