Skip to content

Commit 8b35301

Browse files
committed
check type
1 parent f569d1b commit 8b35301

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

bson/json_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ def _parse_legacy_uuid(doc, json_options):
508508
"""Decode a JSON legacy $uuid to Python UUID."""
509509
if len(doc) != 1:
510510
raise TypeError('Bad $uuid, extra field(s): %s' % (doc,))
511+
if not isinstance(doc["$uuid"], text_type):
512+
raise TypeError('$uuid must be a string: %s' % (doc,))
511513
if json_options.uuid_representation == UuidRepresentation.UNSPECIFIED:
512514
return Binary.from_uuid(uuid.UUID(doc["$uuid"]))
513515
else:

test/test_bson_corpus.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def run_test(self):
210210
decode_extjson(parse_error_case['string'])
211211
raise AssertionError('exception not raised for test '
212212
'case: ' + description)
213-
except (AttributeError, ValueError):
213+
except (TypeError, ValueError):
214214
pass
215215
else:
216216
raise AssertionError('cannot test parseErrors for type ' +

0 commit comments

Comments
 (0)