Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-4603

EJSON serialization breaks on RegExp with /g flag

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: bson-4.7.0
    • Component/s: BSON, EJSON

      What problem are you facing?

      EJSON throws when trying to serialize a plain regexp with a /g flag, which the server does not support directly. bson deserializes/serializes this to an 's' flag instead: https://github.com/mongodb/js-bson/blob/853bbb0441b0e29e5277cd191b515d5a884d8d21/src/parser/serializer.ts#L226

      What driver and relevant dependency versions are you using?

      Latest js-bson

      Steps to reproduce?

      > bson.deserialize(bson.serialize({ a: /asdf/g }))
      { a: /asdf/g }
      > bson.EJSON.serialize({ a: /asdf/g })
      Uncaught BSONError: The regular expression option [g] is not supported
          at new BSONError (/home/addaleax/src/mongosh/node_modules/bson/lib/error.js:23:28)
          at new BSONRegExp (/home/addaleax/src/mongosh/node_modules/bson/lib/regexp.js:37:23)
          at serializeValue (/home/addaleax/src/mongosh/node_modules/bson/lib/extended_json.js:200:18)
          at serializeDocument (/home/addaleax/src/mongosh/node_modules/bson/lib/extended_json.js:238:29)
          at serializeValue (/home/addaleax/src/mongosh/node_modules/bson/lib/extended_json.js:204:16)
          at stringify (/home/addaleax/src/mongosh/node_modules/bson/lib/extended_json.js:363:19)
          at Object.serialize (/home/addaleax/src/mongosh/node_modules/bson/lib/extended_json.js:375:27)
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            anna.henningsen@mongodb.com Anna Henningsen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: