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
Is your feature request related to a problem? Please describe.
Question
when a struct field is a slice with two different element types, the current implementation seems to ignore element of the wrong type. Is this intentional behavior? Is there no error handling for this scenario?
for_, val:=rangevals {
//this check is to handle if the wrong value is providedifconvertedVal:=builtinConverters[f.typ.Elem().Kind()](val); convertedVal.IsValid() {
defaultSlice=reflect.Append(defaultSlice, convertedVal)
}
}
for_, val:=rangevals {
//this check is to handle if the wrong value is providedifconvertedVal:=builtinConverters[f.typ.Elem().Kind()](val); !convertedVal.IsValid() {
// error handling
}
defaultSlice=reflect.Append(defaultSlice, convertedVal)
}
Describe alternatives you have considered.
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered:
Hi @lll-lll-lll-lll, thanks. It seems like this is intentional, but I honestly do not recall the reasons behind the choice because it has been a while since I submitted the PR. Maybe it was because default was considered as something optional and therefore should not break the decoding, no matter what. There is also a test case for this behavior: https://github.com/gorilla/schema/blob/main/decoder_test.go#L2217
I like the idea of failing when a default value that do not match the type is provided. This would enforce correctness and notify when some unexpected value is used. It's certainly a plus.
I'm in agreement with @zak905 here - I think it's better to handle cases with an unexpected value. Please feel free to submit a PR for this change and tag me in it, thanks!
Is there an existing feature request for this?
Is your feature request related to a problem? Please describe.
Question
when a struct field is a slice with two different element types, the current implementation seems to ignore element of the wrong type. Is this intentional behavior? Is there no error handling for this scenario?
Implementation
https://github.com/gorilla/schema/blob/main/decoder.go#L130-L137
example
Describe the solution that you would like.
Describe alternatives you have considered.
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: