fix: handling of map entries with omitted key or value#1348
Merged
alexander-fenster merged 2 commits intoprotobufjs:masterfrom Jul 10, 2020
Merged
fix: handling of map entries with omitted key or value#1348alexander-fenster merged 2 commits intoprotobufjs:masterfrom
alexander-fenster merged 2 commits intoprotobufjs:masterfrom
Conversation
| 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.
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([]).
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 |
This was referenced Feb 13, 2020
Closed
adriancable
approved these changes
Jun 10, 2020
|
@nicolasnoble @alexander-fenster Anything we can do to get this PR reviewed/merged? |
|
Bump. |
alexander-fenster
approved these changes
Jul 10, 2020
|
YES! Thank you so much. |
taylorcode
pushed a commit
to taylorcode/protobuf.js
that referenced
this pull request
Oct 16, 2020
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>
This was referenced May 20, 2022
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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