-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Slice encoding drops empty values rather than encoding them as nil
or default
#215
Labels
Comments
@tombuente Lines 38 to 48 in cd59f2f
|
r.ParseForm()
fmt.Println(r.PostForm["id"], len(r.PostForm["id"])) // [1 15] 3
var decoder = schema.NewDecoder()
// fix
decoder.ZeroEmpty(true)
var i Document
// r.PostForm is a map of our POST form values
err = decoder.Decode(&i, r.PostForm)
if err != nil {
fmt.Println(err)
}
fmt.Println(i.ID, "Length", len(i.ID)) // ID [1 15] Length 2 |
@tombuente Lines 355 to 358 in cd59f2f
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Current Behavior
When called with
id=1, id=, id=15
The behavior is rather unfortunate when decoding values that matter when equal to
""
.For example, when two slices are related to each other.
Now
RowID[0]
andRowName[0]
build a pair. But since gorilla/schema drops empty strings for some reason rather than settings it to Go's default for that value or using the default value defined by tags, the relationship breaks.Expected Behavior
The text was updated successfully, but these errors were encountered: