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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
馃悰 BodyParser does not save empty string to field #1084
Comments
@Fenny Thanks for your consideration. I've added a code sample. |
Hi @sandro , is this issue still exists in the latest version? |
@si3nloong Thanks for the update. I haven't checked against the latest version, but I agree that setting ZeroEmpty to true by default makes sense. Unfortunately, that could break apps that depend on it being false. Is there any way to make ZeroEmpty configurable? |
yes, it is, but I think the break will be minor. Since other famous frameworks also practicing the same way, we should also follow the same practice, to allow the user migrate their app from echo to fiber / fiber to echo seamlessly. |
#1285 merged 馃憤 |
Fiber version
Fiber v2.1.0
Issue description
I'm trying to use BodyParser to save an empty string to a field in a struct, but the empty string will not overwrite the existing data in the field.
The bug disappears when I'm able to set the decoder's zeroEmpty to true, i.e.
decoder.ZeroEmpty(true)
.I wonder if there's a way to allow users to change the decoder when necessary. Perhaps by allowing the user to pass a custom decoder into the BodyParser function?
Code Sample
Sending an empty string to BodyParser does not overwrite the existing value
$ curl -d "title=&body=new_body" localhost:3000/posts
But when sending an empty string when the decoder has
ZeroEmpty
set to true, the decoder does overwrite the existing value.curl -d "title=&body=new_body" localhost:3000/posts_use_empty_string
The text was updated successfully, but these errors were encountered: