Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-3476

Invalid JSON output for Regex

    • Go Drivers
    • Not Needed

      Detailed steps to reproduce the problem?

      Run https://gist.github.com/AlekSi/c2f20c5f6dfa86115be5453b746f47a4

      See this:

      Marshalled

      bson.D{bson.E

      Unknown macro: {Key}

      , bson.E{Key:"regex", Value:bson.Regex

      Unknown macro: {Pattern}

      }}

      as

      {"string":"\"","regex":{"$regularExpression":

      Unknown macro: {"pattern"}

      }}

      Note that the double quote symbol is escaped inside the string but not inside regex. The generated JSON is invalid because of that.

      Definition of done: what must be done to consider the task complete?

      The generated JSON should be valid.

      The exact Go version used, with patch level:

      $ go version

      go version go1.23.5 darwin/arm64

      The exact version of the Go driver used:

      $ go list -m go.mongodb.org/mongo-driver

      go: module go.mongodb.org/mongo-driver: not a known dependency

      The right command is "go list -m go.mongodb.org/mongo-driver/v2":

      go.mongodb.org/mongo-driver/v2 v2.0.0

      Describe how MongoDB is set up. Local vs Hosted, version, topology, load balanced, etc.

      N/A.

      The operating system and version (e.g. Windows 7, OSX 10.8, ...)

      Doesn't matter.

      Security Vulnerabilities{}

      If you’ve identified a security vulnerability in a driver or any other MongoDB project, please report it according to the instructions here

            Assignee:
            qingyang.hu@mongodb.com Qingyang Hu
            Reporter:
            alexey.palazhchenko@ferretdb.io Alexey Palazhchenko
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: