Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions query/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,11 @@ func reflectValue(values url.Values, val reflect.Value, scope string) error {
continue
}

// unwrap interface values so the concrete type's Encoder is used
if sv.Kind() == reflect.Interface && !sv.IsNil() {
sv = sv.Elem()
}

if sv.Type().Implements(encoderType) {
// if sv is a nil pointer and the custom encoder is defined on a non-pointer
// method receiver, set sv to the zero value of the underlying type
Expand Down
8 changes: 8 additions & 0 deletions query/encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ func TestValues_CustomEncodingSlice(t *testing.T) {
}{(*customEncodedStrings)(&[]string{"a", "b"})},
url.Values{"v.0": {"a"}, "v.1": {"b"}},
},

// custom encoded type held in an interface field
{
struct {
V interface{} `url:"v"`
}{customEncodedStrings{"a", "b"}},
url.Values{"v.0": {"a"}, "v.1": {"b"}},
},
}

for _, tt := range tests {
Expand Down
Loading