-
Notifications
You must be signed in to change notification settings - Fork 166
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
Allow calling Closure elements of Maps as methods #199
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.
I think this is ok, but want to get someone else's eyes on it before merging. Thanks!
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.
I don't see anything obviously wrong with this, but wonder a bit if there's additional cases we might want to cover such as Closures with arguments and first-class functions.
@svanoort By Closures with arguments you mean in this same scenario, as Map elements? If so, this covers them as well. Should I add this to the unit test? Also, I don't think I know what you mean by first-class functions. |
@rudolfwalter I think it would be helpful to have Closures taking parameters in the test, yeah. Ignore the comment about functions. |
@svanoort done :) |
@@ -114,6 +116,14 @@ | |||
throw StaticWhitelist.rejectStaticMethod(foundDgmMethod); | |||
} | |||
|
|||
// allow calling Closure elements of Maps as methods | |||
if (receiver instanceof Map) { | |||
Object element = onMethodCall(invoker, receiver, "get", method); |
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.
Not technically correct to delegate to onMethodCall
here: if the whitelist did not pass this particular Map.get(Object)
call but the receiver was allowed to work in some other way like the invokeMethod
below, then we would be breaking something that worked before. OTOH Map.get(Object)
at the interface level is whitelisted, so using the standard whitelist there is no way this would not pass.
Just another example of the problem noted in jenkinsci/groovy-sandbox#7 (comment).
@abayer Kind reminder that this needs to be merged. |
@rudolfwalter Don't worry, I've got this. |
The sandbox rejects valid Groovy code when trying to call a Closure element of a Map as if it were one of the Map's methods. See JENKINS-50843.