Skip to content
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

Merged
merged 5 commits into from
Nov 13, 2018

Conversation

PrashanthCorp
Copy link
Contributor

No description provided.

@PrashanthCorp PrashanthCorp requested a review from a team as a code owner November 9, 2018 01:32
Copy link
Contributor

@StephenWeatherford StephenWeatherford left a 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?

@PrashanthCorp
Copy link
Contributor Author

Added tests.

});

test("test regular expression parsing interoperability - newline", () => {
let text1 = `db.test1.beep.find({ sku: /ker\\n/g })`; // equivalent to user typing out /ker\b/
Copy link
Contributor

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

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/
Copy link
Contributor

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

@@ -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 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better names

@PrashanthCorp PrashanthCorp merged commit c7ef1f1 into master Nov 13, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Apr 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants