PYTHON-2883 Regex decoding error tests in top.json have unexpected, invalid syntax (#721)

This commit is contained in:
Julius Park 2021-09-09 18:32:53 -07:00 committed by GitHub
parent fb38fbe35e
commit 7a4b617b5d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

View File

@ -666,7 +666,11 @@ def _parse_canonical_regex(doc):
if len(regex) != 2:
raise TypeError('Bad $regularExpression must include only "pattern"'
'and "options" components: %s' % (doc,))
return Regex(regex['pattern'], regex['options'])
opts = regex['options']
if not isinstance(opts, str):
raise TypeError('Bad $regularExpression options, options must be '
'string, was type %s' % (type(opts)))
return Regex(regex['pattern'], opts)
def _parse_canonical_dbref(doc):

View File

@ -92,11 +92,11 @@
},
{
"description": "Bad $regularExpression (pattern is number, not string)",
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"$options\" : \"\"}}}"
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": 42, \"options\" : \"\"}}}"
},
{
"description": "Bad $regularExpression (options are number, not string)",
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"$options\" : 0}}}"
"string": "{\"x\" : {\"$regularExpression\" : { \"pattern\": \"a\", \"options\" : 0}}}"
},
{
"description" : "Bad $regularExpression (missing pattern field)",