-
Type:
Bug
-
Resolution: Unresolved
-
Priority:
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
- Create aggregation pipeline with a single $addFields stage:
{ matches: {$regexFindAll: {regex: /\d+/, input: "$data"}}, justString: "\"", }
- Export it to Node.js, C#, Go, Rust, PHP, or Python.
- 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+")
- is duplicated by
-
COMPASS-8933 Invalid python regex codegeneration
-
- Closed
-