unmarshal does not return nil object when value is nil#41
unmarshal does not return nil object when value is nil#41kzys merged 1 commit intocontainerd:mainfrom
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
| } | ||
| } | ||
|
|
||
| if value == nil { |
There was a problem hiding this comment.
IIUC, it should be if len(value) == 0.
There was a problem hiding this comment.
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 <[email protected]>
|
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 paramis nil, it does not mean that typeurl is also empty.When value is nil, the
unmarshalreturnsnil, nildirectly, 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