compass
compass copied to clipboard
fix(bson-transpilers-python-regex): No need to escape `\` in regex
Description
Remove the escape sentence as the returned value is using r string and no need to append double \ to escape characters.
Checklist
- [ ] New tests and/or benchmarks are included
- [ ] Documentation is changed or added
- [X] I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)
Motivation and Context
- [x] Bugfix
- [ ] New feature
- [ ] Dependency update
- [ ] Misc
While using export to python the following query
{message: {$regex: /\d+/}}
will be translated into
{
'message': {
'$regex': re.compile(r"\\d+")
}
}
The expected outcome should be:
{
'message': {
'$regex': re.compile(r"\d+")
}
}
or
{
'message': {
'$regex': re.compile("\\d+")
}
}
Since r string(r"") is used in the return value, an extra escape for the \ is redundant and breaks the semantic of the original regex.
Open Questions
Dependents
Types of changes
- [ ] Backport Needed
- [x] Patch (non-breaking change which fixes an issue)
- [ ] Minor (non-breaking change which adds functionality)
- [ ] Major (fix or feature that would cause existing functionality to change)