Skip to content

Commit a4c7442

Browse files
committed
Keep only tests that change state across the fix
The raw Map and non-domain cases passed before this change and after it, so they documented behaviour rather than protecting it, and are dropped. What is added instead all fails without the fix, each for a distinct reason: - a property declared Collection rather than List or Set, so the branch is reached through a third declared type, - elements arriving as a DataBindingSource rather than a Map, which is the other item shape that branch instantiates, - deny-by-default enabled with the property allowlisted, which shows the loss is not gated by the opt-in: the element is an empty Object there too, and the property binds, so the failure is the data being destroyed rather than the binding being denied.
1 parent 1829d42 commit a4c7442

1 file changed

Lines changed: 44 additions & 8 deletions

File tree

grails-test-suite-persistence/src/test/groovy/grails/web/databinding/GrailsWebDataBinderSpec.groovy

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import spock.lang.Unroll
2828
import org.springframework.context.support.StaticMessageSource
2929

3030
import grails.config.Settings
31+
import grails.util.Holders
3132
import grails.databinding.BindUsing
3233
import grails.databinding.BindingFormat
3334
import grails.databinding.DataBindingSource
@@ -1982,32 +1983,66 @@ class GrailsWebDataBinderSpec extends Specification implements DataTest {
19821983
obj.rawList[1].param == 'status=pending'
19831984
}
19841985

1985-
void 'test binding maps into a raw Map property preserves the map values'() {
1986+
void 'test binding maps into a raw Set property preserves the map elements'() {
19861987
given:
19871988
def obj = new RawCollectionContainer()
19881989

19891990
when:
19901991
binder.bind(obj, new SimpleMapDataBindingSource([
1991-
rawMap: [first: [label: 'Answered', param: 'status=resolved']]
1992+
rawSet: [[label: 'Answered', param: 'status=resolved']]
19921993
]))
19931994

19941995
then:
1995-
obj.rawMap.first instanceof Map
1996-
obj.rawMap.first.label == 'Answered'
1996+
obj.rawSet.every { it instanceof Map }
1997+
obj.rawSet.first().label == 'Answered'
19971998
}
19981999

1999-
void 'test binding maps into a raw Set property preserves the map elements'() {
2000+
void 'test binding maps into a raw Collection-typed property'() {
2001+
given:
2002+
def obj = new RawCollectionContainer()
2003+
2004+
when:
2005+
binder.bind(obj, new SimpleMapDataBindingSource([rawCollection: [[label: 'Answered']]]))
2006+
2007+
then:
2008+
obj.rawCollection.every { it instanceof Map }
2009+
obj.rawCollection[0].label == 'Answered'
2010+
}
2011+
2012+
void 'test binding DataBindingSource items into a raw collection'() {
20002013
given:
20012014
def obj = new RawCollectionContainer()
20022015

20032016
when:
20042017
binder.bind(obj, new SimpleMapDataBindingSource([
2005-
rawSet: [[label: 'Answered', param: 'status=resolved']]
2018+
rawList: [new SimpleMapDataBindingSource([label: 'Answered'])]
20062019
]))
20072020

20082021
then:
2009-
obj.rawSet.every { it instanceof Map }
2010-
obj.rawSet.first().label == 'Answered'
2022+
obj.rawList.size() == 1
2023+
obj.rawList[0].getClass() != Object
2024+
}
2025+
2026+
void 'test binding maps into a raw collection with deny-by-default enabled'() {
2027+
given: 'the opt-in hardening turned on, and the property explicitly allowlisted'
2028+
def originalConfig = Holders.config
2029+
Holders.setConfig(new PropertySourcesConfig([(Settings.DATABINDING_DENY_BY_DEFAULT): true]))
2030+
DataBindingUtils.clearBindingCaches()
2031+
def obj = new RawCollectionContainer()
2032+
2033+
when:
2034+
binder.bind(obj, new SimpleMapDataBindingSource([
2035+
rawList: [[label: 'Answered', param: 'status=resolved']]
2036+
]), null, ['rawList'], null, null)
2037+
2038+
then: 'the elements are still maps, as they are with the hardening off'
2039+
obj.rawList.size() == 1
2040+
obj.rawList[0] instanceof Map
2041+
obj.rawList[0].label == 'Answered'
2042+
2043+
cleanup:
2044+
Holders.setConfig(originalConfig)
2045+
DataBindingUtils.clearBindingCaches()
20112046
}
20122047
}
20132048

@@ -2017,6 +2052,7 @@ class RawCollectionContainer {
20172052
List rawList = []
20182053
Map rawMap = [:]
20192054
Set rawSet = []
2055+
Collection rawCollection = []
20202056
}
20212057

20222058
@Entity

0 commit comments

Comments
 (0)