Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-98936

Fix encoding of regex patterns returned from $function

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • Hide
      Enterprise test> db.coll.runCommand({ aggregate: 1, pipeline: [{ "$documents": { "$function": { "body": "function(arg1){ return arg1; }", "args": [{ "$map": { "input": [false], "in": { "$setField": { "field": "obj.obj.obj.bool", "input": { "obj": { "str": "relationships" } }, "value": { "$function": { "body": "function(){ return /^C(?:otton|heese)/; }", "args": [], "lang": "js" } } } } } }], "lang": "js" } } }], cursor: {}, maxTimeMS: 30000 })
      {
        cursor: {
          firstBatch: [
            {
              obj: { str: 'relationships' },
              'obj.obj.obj.bool': /^C(?:otton|heese)\//
            }
          ],
          id: Long('0'),
          ns: 'test.$cmd.aggregate'
        },
        ok: 1
      }
      Enterprise test> db.coll.runCommand({ aggregate: 1, pipeline: [{ "$documents": { "$function": { "body": "function(arg1){ return arg1; }", "args": [{ "$map": { "input": [false], "in": { "$setField": { "field": "obj.obj.obj.bool", "input": { "obj": { "str": "relationships" } }, "value": { "$function": { "body": "function(){ return new RegExp('^C(?:otton|heese)'); }", "args": [], "lang": "js" } } } } } }], "lang": "js" } } }], cursor: {}, maxTimeMS: 30000 })
      {
        cursor: {
          firstBatch: [
            {
              obj: { str: 'relationships' },
              'obj.obj.obj.bool': /^C(?:otton|heese)\//
            }
          ],
          id: Long('0'),
          ns: 'test.$cmd.aggregate'
        },
        ok: 1
      }
      
      Show
      Enterprise test> db.coll.runCommand({ aggregate: 1, pipeline: [{ "$documents": { "$function": { "body": "function(arg1){ return arg1; }", "args": [{ "$map": { "input": [false], "in": { "$setField": { "field": "obj.obj.obj.bool", "input": { "obj": { "str": "relationships" } }, "value": { "$function": { "body": "function(){ return /^C(?:otton|heese)/; }", "args": [], "lang": "js" } } } } } }], "lang": "js" } } }], cursor: {}, maxTimeMS: 30000 }) { cursor: { firstBatch: [ { obj: { str: 'relationships' }, 'obj.obj.obj.bool': /^C(?:otton|heese)\// } ], id: Long('0'), ns: 'test.$cmd.aggregate' }, ok: 1 } Enterprise test> db.coll.runCommand({ aggregate: 1, pipeline: [{ "$documents": { "$function": { "body": "function(arg1){ return arg1; }", "args": [{ "$map": { "input": [false], "in": { "$setField": { "field": "obj.obj.obj.bool", "input": { "obj": { "str": "relationships" } }, "value": { "$function": { "body": "function(){ return new RegExp('^C(?:otton|heese)'); }", "args": [], "lang": "js" } } } } } }], "lang": "js" } } }], cursor: {}, maxTimeMS: 30000 }) { cursor: { firstBatch: [ { obj: { str: 'relationships' }, 'obj.obj.obj.bool': /^C(?:otton|heese)\// } ], id: Long('0'), ns: 'test.$cmd.aggregate' }, ok: 1 }
    • QE 2025-01-20

      A function that returns a bare regex that ends with a forward lookahead (see examples below with ^C(?:otton|heese)) mistakenly returns a regex with a / appended. This can be confirmed by checking the result of ExpressionFunction::evaluate().

            Assignee:
            jan.steemann@mongodb.com Jan Steemann
            Reporter:
            william.qian@mongodb.com William Qian
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated: