Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-3773

libbson rejects regular expressions with no options field

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • 1.18.0, 1.18.0-alpha
    • 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

            Assignee:
            benji.rewis@mongodb.com Benji Rewis (Inactive)
            Reporter:
            julius.park@mongodb.com Julius Park (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: