@@ -143,7 +143,6 @@ func isEmpty(t reflect.Type, value []string) bool {
143
143
144
144
// decode fills a struct field using a parsed path.
145
145
func (d * Decoder ) decode (v reflect.Value , path string , parts []pathPart , values []string ) error {
146
-
147
146
// Get the field walking the struct fields by index.
148
147
for _ , name := range parts [0 ].path {
149
148
if v .Type ().Kind () == reflect .Ptr {
@@ -185,7 +184,8 @@ func (d *Decoder) decode(v reflect.Value, path string, parts []pathPart, values
185
184
186
185
// Get the converter early in case there is one for a slice type.
187
186
conv := d .cache .converter (t )
188
- if conv == nil && t .Kind () == reflect .Slice {
187
+ m := isTextUnmarshaler (v )
188
+ if conv == nil && t .Kind () == reflect .Slice && m .IsSlice {
189
189
var items []reflect.Value
190
190
elemT := t .Elem ()
191
191
isPtrElem := elemT .Kind () == reflect .Ptr
@@ -209,7 +209,7 @@ func (d *Decoder) decode(v reflect.Value, path string, parts []pathPart, values
209
209
if d .zeroEmpty {
210
210
items = append (items , reflect .Zero (elemT ))
211
211
}
212
- } else if m := isTextUnmarshaler ( v ); m .IsValid {
212
+ } else if m .IsValid {
213
213
u := reflect .New (elemT )
214
214
if m .IsPtr {
215
215
u = reflect .New (reflect .PtrTo (elemT ).Elem ())
@@ -297,7 +297,7 @@ func (d *Decoder) decode(v reflect.Value, path string, parts []pathPart, values
297
297
Index : - 1 ,
298
298
}
299
299
}
300
- } else if m := isTextUnmarshaler ( v ); m .IsValid {
300
+ } else if m .IsValid {
301
301
// If the value implements the encoding.TextUnmarshaler interface
302
302
// apply UnmarshalText as the converter
303
303
if err := m .Unmarshaler .UnmarshalText ([]byte (val )); err != nil {
@@ -346,6 +346,7 @@ func isTextUnmarshaler(v reflect.Value) unmarshaler {
346
346
}
347
347
if t .Kind () == reflect .Slice {
348
348
// if t is a pointer slice, check if it implements encoding.TextUnmarshaler
349
+ m .IsSlice = true
349
350
if t = t .Elem (); t .Kind () == reflect .Ptr {
350
351
t = reflect .PtrTo (t .Elem ())
351
352
v = reflect .Zero (t )
@@ -364,6 +365,7 @@ func isTextUnmarshaler(v reflect.Value) unmarshaler {
364
365
// unmarshaller contains information about a TextUnmarshaler type
365
366
type unmarshaler struct {
366
367
Unmarshaler encoding.TextUnmarshaler
368
+ IsSlice bool
367
369
IsPtr bool
368
370
IsValid bool
369
371
}
0 commit comments