Skip to content

Commit 1b84d79

Browse files
committed
PYTHON-2883 Regex decoding error tests in top.json have unexpected, invalid syntax (mongodb#721)
1 parent 1b024ad commit 1b84d79

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

bson/json_util.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,11 @@ def _parse_canonical_regex(doc):
666666
if len(regex) != 2:
667667
raise TypeError('Bad $regularExpression must include only "pattern"'
668668
'and "options" components: %s' % (doc,))
669-
return Regex(regex['pattern'], regex['options'])
669+
opts = regex['options']
670+
if not isinstance(opts, str):
671+
raise TypeError('Bad $regularExpression options, options must be '
672+
'string, was type %s' % (type(opts)))
673+
return Regex(regex['pattern'], opts)
670674

671675

672676
def _parse_canonical_dbref(doc):

test/bson_corpus/top.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@
9292
},
9393
{
9494
"description": "Bad $regularExpression (pattern is number, not string)",
95-
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"$options\" : \"\"}}}"
95+
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"options\" : \"\"}}}"
9696
},
9797
{
9898
"description": "Bad $regularExpression (options are number, not string)",
99-
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"$options\" : 0}}}"
99+
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"options\" : 0}}}"
100100
},
101101
{
102102
"description" : "Bad $regularExpression (missing pattern field)",

0 commit comments

Comments
 (0)