Skip to content

Commit

Permalink
GRAILS-11472 - fix binding empty strings to fields marked with @Bindi…
Browse files Browse the repository at this point in the history
…ngFormat
  • Loading branch information
Jeff Scott Brown committed Jun 4, 2014
1 parent 08acf41 commit 5cacb20
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ class SimpleDataBinder implements DataBinder {
def formattedConverter = formattedValueConvertersionHelpers[field.type]
if (formattedConverter) {
converter = { SimpleMapDataBindingSource source ->
def value = source.getPropertyValue field.name
def value = preprocessValue(source.getPropertyValue(field.name))
def convertedValue = null
if(value != null) {
convertedValue = formattedConverter.convert (value, formattingValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,29 @@ class GrailsWebDataBinderSpec extends Specification {
!publisher.hasErrors()
publisher.name == 'Some Publisher'
}

@Issue('GRAILS-11472')
void 'test binding an empty string to a Date marked with @BindingFormat'() {
given:
def book = new DataBindingBook()

when: 'a valid date string is bound'
binder.bind book, [datePublished: '11151969'] as SimpleMapDataBindingSource

then: 'the date is initialized'
!book.hasErrors()
book.datePublished
Calendar.NOVEMBER == book.datePublished.month
15 == book.datePublished.date
69 == book.datePublished.year

when: 'an empty string is bound'
binder.bind book, [datePublished: ''] as SimpleMapDataBindingSource

then: 'the date is null'
book.datePublished == null
!book.hasErrors()
}
}

@Entity
Expand Down

0 comments on commit 5cacb20

Please sign in to comment.