You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix panic when the decoding pointer type with custom decoding function (#68)
## Fixes Or Enhances
When a pointer type has a custom decoder and the decoded value is nil,
we get a panic.
Example
```go
func main() {
type CustomTime *time.Time
type TestError struct {
CT CustomTime
}
var test TestError
decoder = form.NewDecoder()
decoder.RegisterCustomTypeFunc(func(s []string) (interface{}, error) {
if s[0] == "" {
return nil, nil
}
parsed, err := time.Parse(time.RFC3339, s[0])
if err != nil {
return nil, err
}
return CustomTime(&parsed), nil
}, CustomTime(nil))
values := url.Values{
"CT": []string{""},
}
decoder.Decode(&test, values)
}
```
```
panic: reflect: call of reflect.Value.Set on zero Value
```
This PR specifically handles the case for the case when the type is a
pointer.
**Make sure that you've checked the boxes below before you submit PR:**
- [x] Tests exist or have been written that cover this particular
change.
@go-playground/admins
0 commit comments