-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: handling of map entries with omitted key or value #1348
fix: handling of map entries with omitted key or value #1348
Conversation
src/decoder.js
Outdated
if (type === "string") gen | ||
("value=\"%s\"", types.defaults[type]); | ||
else if (types.defaults[type] !== undefined) gen | ||
("value=%s", types.defaults[type]); |
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.
if type === "bytes" then this tries to insert the default value of an empty array with %s and it ends up inserting empty string "" instead of "[]". This is because %s calls String([]) when we need %j here so we use JSON.stringify([]).
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.
Thanks, fixed.
According to [1], map encoding must be compatible with a repeated message using indices 1 and 2 for key and value. In particular this implies that both key and value may be omitted when they are equal to the default value - which some protobuf implementations like protobuf-c actually do. The comments in the added testcase are based on the output of protobuf-inspector [2]. [1] https://developers.google.com/protocol-buffers/docs/proto3#backwards-compatibility [2] https://github.com/jmendeth/protobuf-inspector Based-on-patch-by: Shrimpz <Shrimpz@qq.com>
b0a8360
to
6b42837
Compare
@schiffermtq Thank you so much for this PR! This should also fix #1293 |
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.
This looks (and works) great.
@nicolasnoble @alexander-fenster Anything we can do to get this PR reviewed/merged? |
Bump. |
YES! Thank you so much. |
According to [1], map encoding must be compatible with a repeated message using indices 1 and 2 for key and value. In particular this implies that both key and value may be omitted when they are equal to the default value - which some protobuf implementations like protobuf-c actually do. The comments in the added testcase are based on the output of protobuf-inspector [2]. [1] https://developers.google.com/protocol-buffers/docs/proto3#backwards-compatibility [2] https://github.com/jmendeth/protobuf-inspector Based-on-patch-by: Shrimpz <Shrimpz@qq.com> Co-authored-by: Alexander Fenster <fenster@google.com>
According to [1], map encoding must be compatible with a repeated message
using indices 1 and 2 for key and value. In particular this implies that
both key and value may be omitted when they are equal to the default
value - which some protobuf implementations like protobuf-c actually do.
The comments in the added testcase are based on the output of
protobuf-inspector [2].
[1] https://developers.google.com/protocol-buffers/docs/proto3#backwards-compatibility
[2] https://github.com/jmendeth/protobuf-inspector
This is a cleaned up version of #1087:
Supersedes #845
Supersedes #1087
Fixes #843
Fixes #960
Fixes #1087