-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pad slashes in /regex/ syntax to provide parity with $regex syntax #933
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are the tests?
Added tests. |
test/mongoGetCommand.test.ts
Outdated
}); | ||
|
||
test("test regular expression parsing interoperability - newline", () => { | ||
let text1 = `db.test1.beep.find({ sku: /ker\\n/g })`; // equivalent to user typing out /ker\b/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit your comment is wrong
test/mongoGetCommand.test.ts
Outdated
assert.deepEqual([generatedRegExp1.flags, generatedRegExp1.source], ["g", "ker\\n"]); | ||
}); | ||
test("test regular expression parsing interoperability - carriage return", () => { | ||
let text1 = `db.test1.beep.find({ sku: /ker\\r/g })`; // equivalent to user typing out /ker\b/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit your comment is wrong
src/mongo/MongoScrapbook.ts
Outdated
@@ -404,7 +396,8 @@ class FindMongoCommandsVisitor extends MongoVisitor<MongoCommand[]> { | |||
// It is intended for the errors thrown here to be handled by the catch block. | |||
let tokenObject = new RegExp(pattern, flags); | |||
tokenObject = tokenObject; | |||
return { $regex: pattern, $options: flags }; | |||
// we are passing back a $regex annotation, hence we ensure parity wit the $regex syntax | |||
return { $regex: this.padRegexEscape(pattern), $options: flags }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better names
No description provided.