-
Notifications
You must be signed in to change notification settings - Fork 19
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
unmarshal does not return nil object when value is nil #41
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #41 +/- ##
=======================================
Coverage 68.90% 68.90%
=======================================
Files 1 1
Lines 119 119
=======================================
Hits 82 82
Misses 28 28
Partials 9 9
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report in Codecov by Sentry. |
5f76736
to
1d95db6
Compare
types.go
Outdated
@@ -216,6 +212,10 @@ func unmarshal(typeURL string, value []byte, v interface{}) (interface{}, error) | |||
} | |||
} | |||
|
|||
if value == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIUC, it should be if len(value) == 0
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some thought, I decided to remove this judgment and bring the behavior in here back to be consistent with v1typeurl.
For proto, the empty value(nil
, []byte{}
) needs to set all the fields of the incoming v parameter to empty, because maybe the incoming v
object already has some fields set
For json, it should not be nil or []byte{}, a valid null value is "null" or '{}', '[]', if value is nil or []byte{}, then json.Marshal
will return an error
Signed-off-by: Iceber Gu <wei.cai-nat@daocloud.io>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I will push a tag next Monday if no one takes this. @Iceber |
@fuweid Could we release 2.1.1 now? 😀 |
@Iceber Done. |
issue: containerd/containerd#8392
For
unmarshal
, thevalue param
is nil, it does not mean that typeurl is also empty.When value is nil, the
unmarshal
returnsnil, nil
directly, which becomes cumbersome to use and skips the check for typeurl.Always have unmarshal return a non-nil object when
err is nil
, which is consistent with the behavior of v1 typeurl