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

fix(rule,check): allow function ids for matches property in rule.configure #2423

Merged
merged 2 commits into from
Jul 28, 2020

Conversation

straker
Copy link
Contributor

@straker straker commented Jul 27, 2020

@downzer0 discovered this one when trying to configure a rule with a matches function ID. I added tests to ensure this should work now as well as throw a more helpful message as the default was eval the string as code and you'd get a thing is not defined error which was super unhelpful. So now you should get an error with the name of the string you used.

Reviewer checks

Required fields, to be filled out by PR reviewer(s)

  • Follows the commit message policy, appropriate for next version
  • Code is reviewed for security

@straker straker requested a review from a team as a code owner July 27, 2020 17:26
@@ -9,7 +9,14 @@ export function createExecutionContext(spec) {
return metadataFunctionMap[spec];
}

return new Function('return ' + spec + ';')();
// execution contexts can only be functions
if (/^\s*function[\s\w]*\(/.test(spec)) {
Copy link
Member

Choose a reason for hiding this comment

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

What about "arrow functions"?

return this.evaluate();
};
var check = new Check({
evaluate: 'function () { return "foo"; }'
Copy link
Member

Choose a reason for hiding this comment

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

What happens if we do this:

evaluate: '() => "foo"'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As far as I know we don't allow that. Although it is possible, we only support doT.js template output which uses functions.

@WilcoFiers do you find this a problem (especially since we deprecated this?)

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a problem, no.

return this.evaluate();
};
var check = new Check({
evaluate: 'function () { return "foo"; }'
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this is a problem, no.

@straker straker merged commit 3ccb781 into develop Jul 28, 2020
@straker straker deleted the configure branch July 28, 2020 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants