-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: 1.17.0
-
Component/s: libbson
This originally appeared in a test failure in python-bsonjs.
This is the failing test: https://github.com/mongodb-labs/python-bsonjs/blob/2947fc596c76fa82e47b903785bf1411f1c9be05/test/test_bsonjs.py#L146-L149. It fails with these logs:
ERROR: test_regex (test.test_bsonjs.TestBsonjs) ---------------------------------------------------------------------- Traceback (most recent call last): File "/home/travis/build/mongodb-labs/python-bsonjs/test/test_bsonjs.py", line 147, in test_regex res = bsonjs_loads('{"r": {"$regex": "a*b"}}')['r'] File "/home/travis/build/mongodb-labs/python-bsonjs/test/test_bsonjs.py", line 63, in bsonjs_loads return to_object(bsonjs.loads(json_str)) ValueError: Missing "$options" after "$regex"
This specific test is loading legacy regex syntax without the $options field:
{"r": {"$regex": "a*b"}}
Though based on _bson_json_read_append_regex also rejects the canonical representation of a regex if the options field was missing, like:
{"r": {"$regularExpression": { "pattern": "a*b" }}
If libbson is passing the BSON corpus tests, I imagine it is not required by the spec that we permit regular expressions without options field. But if other tools may produce this (as the comment in test_bsonjs.py says), it seems worthwhile to not reject.
For more info about regex representation in JSON, see the extended JSON spec: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst