Uploaded image for project: 'Compass '
  1. Compass
  2. COMPASS-7690

In aggregation pipepline regex expression is incorrectly escaped when exporting to some languages

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Export to Language
    • None
    • Environment:
      OS: macosx
      node.js / npm versions: v21.6.2
      Additional info: Compass version 1.42.1
    • Developer Tools

      Problem Statement/Rationale

      When exporting aggregation pipeline to some languages, Regex expression is escaped incorrectly

      Steps to Reproduce

      1. Create aggregation pipeline with a single $addFields stage:
        {
          matches: {$regexFindAll: {regex: /\d+/, input: "$data"}},
          justString: "\"",
        } 
      1. Export it to Node.js, C#, Go, Rust, PHP, or Python.
      2. Observe generated regex string.

      Expected Results

      Regex expression in these languages are generated as regular string, so to produce string "\d", we need to escape \, otherwise we will get just "d".
      Nodejs: new RegExp('
      d+')
      C#: new Regex("
      d+")
      Go: primitive.Regex{Pattern: "
      d+"}
      Rust: pattern: "
      d+".to_string() *
      PHP: new Regex("
      d+")

      * - note: in Rust there is r".." for regex strings, so maybe we can use pattern: r"\d+".to_string() instead.

      Actual Results

      We don't escape \, so instead of digits, we match just the letter d.
      Nodejs: new RegExp('\d+')
      C#: new Regex("\d+")
      Go: primitive.Regex{Pattern: "\d+"}
      Rust: pattern: "\d+".to_string()
      PHP: new Regex("\d+")

            Assignee:
            Unassigned Unassigned
            Reporter:
            ivan.fefer@mongodb.com Ivan Fefer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: