Add missing error message to InvalidBSON error
Signed-off-by: liubo <liubo1@xfusion.com> (cherry picked from commit a83c461dba8c95d02f5ae7028f57e8eeac9b09f1)
This commit is contained in:
parent
5ed932cd7e
commit
266b0e8122
@ -0,0 +1,46 @@
|
|||||||
|
From 9e01a6bf1d081c62ac2173f666234de159397e0c Mon Sep 17 00:00:00 2001
|
||||||
|
From: Shane Harvey <shane.harvey@mongodb.com>
|
||||||
|
Date: Fri, 2 Apr 2021 10:17:04 -0700
|
||||||
|
Subject: [PATCH] PYTHON-2631 Add missing error message to InvalidBSON error
|
||||||
|
(#589)
|
||||||
|
|
||||||
|
(cherry picked from commit cc029a1e6208863eaab453777363d3935b927f32)
|
||||||
|
---
|
||||||
|
bson/_cbsonmodule.c | 2 +-
|
||||||
|
test/test_bson.py | 7 +++++++
|
||||||
|
2 files changed, 8 insertions(+), 1 deletion(-)
|
||||||
|
|
||||||
|
diff --git a/bson/_cbsonmodule.c b/bson/_cbsonmodule.c
|
||||||
|
index 34f3ab6f..1522bb0a 100644
|
||||||
|
--- a/bson/_cbsonmodule.c
|
||||||
|
+++ b/bson/_cbsonmodule.c
|
||||||
|
@@ -2621,7 +2621,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;
|
||||||
|
diff --git a/test/test_bson.py b/test/test_bson.py
|
||||||
|
index ad726f71..f75da3d2 100644
|
||||||
|
--- a/test/test_bson.py
|
||||||
|
+++ b/test/test_bson.py
|
||||||
|
@@ -373,6 +373,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"
|
||||||
|
--
|
||||||
|
2.42.0.windows.2
|
||||||
|
|
||||||
@ -1,11 +1,12 @@
|
|||||||
Name: python-pymongo
|
Name: python-pymongo
|
||||||
Version: 3.11.3
|
Version: 3.11.3
|
||||||
Release: 1
|
Release: 2
|
||||||
License: Apache License 2.0
|
License: Apache License 2.0
|
||||||
Summary: PyMongo - the Python driver for MongoDB
|
Summary: PyMongo - the Python driver for MongoDB
|
||||||
URL: https://github.com/mongodb/mongo-python-driver
|
URL: https://github.com/mongodb/mongo-python-driver
|
||||||
Source0: https://files.pythonhosted.org/packages/72/82/e7196f2f69318dd206db26db68fcfa0ff821d88fbca6d0f0c7b678ba0353/pymongo-3.11.3.tar.gz
|
Source0: https://files.pythonhosted.org/packages/72/82/e7196f2f69318dd206db26db68fcfa0ff821d88fbca6d0f0c7b678ba0353/pymongo-3.11.3.tar.gz
|
||||||
Patch01: 0001-Use-ssl.match_hostname-from-the-Python-stdlib.patch
|
Patch01: 0001-Use-ssl.match_hostname-from-the-Python-stdlib.patch
|
||||||
|
Patch02: 0001-PYTHON-2631-Add-missing-error-message-to-InvalidBSON.patch
|
||||||
|
|
||||||
BuildRequires: python3-devel python3-setuptools
|
BuildRequires: python3-devel python3-setuptools
|
||||||
BuildRequires: python3-sphinx gcc
|
BuildRequires: python3-sphinx gcc
|
||||||
@ -85,6 +86,9 @@ python3 setup.py test
|
|||||||
%{_pkgdocdir}
|
%{_pkgdocdir}
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Wed Nov 8 2023 liubo <liubo1@xfusion.com> - 3.11.3-2
|
||||||
|
- Add missing error message to InvalidBSON error
|
||||||
|
|
||||||
* Fri Aug 06 2021 OpenStack_SIG <openstack@openeuler.org> - 3.11.3-1
|
* Fri Aug 06 2021 OpenStack_SIG <openstack@openeuler.org> - 3.11.3-1
|
||||||
- Update version to 3.11.3
|
- Update version to 3.11.3
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user