Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Not A Bug
-
Affects Version/s: 1.3.7
-
Fix Version/s: 2.0-M2
-
Component/s: Controllers
-
Labels:
-
Testcase included:yes
Description
When bindData() is given an empty list of properties to include, it binds everything (but nothing should be bound).
class FooController {
def index = {
def foo = new Foo()
bindData(foo, params, [include: []])
foo
}
}
class Foo {
String bar
}
class FooControllerIntegrationTest extends GroovyTestCase {
void testBindDataIncludeNothing() {
def controller = new FooController()
controller.params << [ bar: 'bad' ]
assert controller.index().bar == null
}
}
fails with
Assertion failed: assert controller.index().bar == null | | | | | | bad false | Foo@1b4a4fd2 FooController@2bbe71fd
However, if the include list is not empty (and doesn't include 'bar'), then bar is not bound.
The original description here says "but nothing should be bound". Is that really correct? That isn't how the Spring DataBinder class works. It says that if allowedFields is empty then a field is allowed as long as it isn't included in the explicit excludes.
... protected boolean isAllowed(String field) { String[] allowed = getAllowedFields(); String[] disallowed = getDisallowedFields(); return ((ObjectUtils.isEmpty(allowed) || PatternMatchUtils.simpleMatch(allowed, field)) && (ObjectUtils.isEmpty(disallowed) || !PatternMatchUtils.simpleMatch(disallowed, field))); } ...We can circumvent this by adding logic of our own in GrailsDataBinder but I am not sure that is the right thing to do.
Should we change this behavior or leave it as is?