Skip to content

Commit 940e7f4

Browse files
committed
PYTHON-3028 $regex as a field name does not allow for non-string values (mongodb#807)
1 parent b60e220 commit 940e7f4

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

test/test_json_util.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,15 @@ def test_regex_validation(self):
297297
doc = {"$regex": ""}
298298
self.assertIsInstance(json_util.loads(json.dumps(doc)), Regex)
299299

300+
def test_regex_validation(self):
301+
non_str_types = [10, {}, []]
302+
docs = [{"$regex": i} for i in non_str_types]
303+
for doc in docs:
304+
self.assertEqual(doc, json_util.loads(json.dumps(doc)))
305+
306+
doc = {"$regex": ""}
307+
self.assertIsInstance(json_util.loads(json.dumps(doc)), Regex)
308+
300309
def test_minkey(self):
301310
self.round_trip({"m": MinKey()})
302311

0 commit comments

Comments
 (0)