Skip to content

Commit

Permalink
[FIXED JENKINS-50906] Allow foo() for Script binding closure variables
Browse files Browse the repository at this point in the history
  • Loading branch information
abayer committed Aug 8, 2018
1 parent 23fdbbb commit 6d1e026
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ final class SandboxInterceptor extends GroovyInterceptor {
}
}

// Allow calling closure variables from a script binding as methods
if (receiver instanceof Script) {
Script s = (Script)receiver;
Object var = s.getBinding().getVariable(method);
if (var instanceof Closure) {
return onMethodCall(invoker, var, "call", args);
}
}

// if no matching method, look for catchAll "invokeMethod"
try {
receiver.getClass().getMethod("invokeMethod", String.class, Object.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1089,4 +1089,10 @@ public void callClosureElementOfMapAsMethod() throws Exception {
assertEvaluate(new GenericWhitelist(), "a=hello,b=10", "def m = [ f: {a,b -> return \"a=${a},b=${b}\"} ]; m.f('hello',10)");
assertEvaluate(new GenericWhitelist(), 2, "def m = [ f: {it.size()} ]; m.f(foo:0, bar:1)");
}

@Issue("JENKINS-50906")
@Test
public void scriptBindingClosureVariableCall() throws Exception {
assertEvaluate(new GenericWhitelist(), true, "def func = { 1 }; this.func2 = { 1 }; return func() == func2();\n");
}
}

0 comments on commit 6d1e026

Please sign in to comment.