Commit 212b1c4
authored
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/admins1 parent 8785d3c commit 212b1c4
2 files changed
+57
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
195 | 203 | | |
196 | | - | |
197 | 204 | | |
198 | 205 | | |
199 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
830 | 830 | | |
831 | 831 | | |
832 | 832 | | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
833 | 837 | | |
834 | | - | |
835 | | - | |
836 | | - | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
837 | 847 | | |
838 | 848 | | |
839 | 849 | | |
840 | | - | |
841 | | - | |
842 | | - | |
| 850 | + | |
| 851 | + | |
| 852 | + | |
| 853 | + | |
| 854 | + | |
| 855 | + | |
| 856 | + | |
| 857 | + | |
| 858 | + | |
843 | 859 | | |
844 | 860 | | |
845 | 861 | | |
846 | 862 | | |
847 | 863 | | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
848 | 884 | | |
849 | 885 | | |
850 | 886 | | |
851 | 887 | | |
852 | 888 | | |
853 | 889 | | |
854 | 890 | | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
855 | 898 | | |
856 | 899 | | |
857 | 900 | | |
| |||
0 commit comments