[Regex] Handling escape characters
PrashanthCorp opened this issue · comments
Our handling of escape(d) characters needs some love. This issue will catalog the use-cases that don't work. Please add any issue with regex or escaping characters under this issue.
-
db.heroes.find({s: /a\/}) - Fine
db.heroes.find({s: /a\/}) //comment - Error -
db.coll.insert({s: "a\\b"}) - inserts a document "a\\\\b"
Some use-cases not working
- regex fail
db.my-collection.insert({
"valid_date": {
"type": "string",
"description": "A date time, format YYYY-MM-DDTHH:MM:SS",
"pattern": "([12]\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\d|3[01]))T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]"
}
})
inserts
{
"_id" : ObjectId("5c188e72ee87464108fdf112"),
"valid_date" : {
"type" : "string",
"description" : "A date time, incoming format is YYYY-MM-DDTHH:MM:SS",
"pattern" : "([12]\\\\d{3}-(0[1-9]|1[0-2])-(0[1-9]|[12]\\\\d|3[01]))T(2[0-3]|[01][0-9]):[0-5][0-9]:[0-5][0-9]"
}
}
- Escaped quotes in a string
db.my-collection.insert({
"my-string": "quoted text in a string \"some quoted text\" should be good",
})
inserts
{
"_id" : ObjectId("5c188f98ee87464108fdf113"),
"my-string" : "quoted text in a string \\\"some quoted text\\\" should be good"
}
@codermrrob Thanks for letting us know. How important is this fix?
Both these issues hit us a lot. So much that the extension is not practically usable in our development team, which is disappointing because we love vscode and use it for building out & editing the json objects we want to store and query, so this extension should be a natural fit. Unfortunately not because of the amount of json schema we use - so we hit the regex issue a lot.
I guess will be the same for anyone who is storing json schema objects/regex expression.
FYI, The database we are using is MongoDB.Atlas and the output from the inserted object was queried and copied from the tree view in Studio3T.
And I notice the string example I posted was incorrect. The inserted object should be:
{
"_id" : ObjectId("5c188f98ee87464108fdf113"),
"my-string" : "quoted text in a string \\"some quoted text\\" should be good"
}
(one less '\')
This issue has become stale and is at risk of being closed. The community has 60 days to upvote the issue. If it receives 5 upvotes we will keep it open and take another look. If not, we will close it. To learn more about how we handle issues, please see our documentation.
Happy Coding!
🙁 In the last 60 days, this issue has received less than 5 community upvotes and we closed it. Still a big Thank You to you for taking the time to create it! To learn more about how we handle issues, please see our documentation.
Happy Coding!