Skip to content
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 decoding of maps to match conformance tests #391

Merged
merged 6 commits into from
Jan 4, 2025

Conversation

v0idpwn
Copy link
Collaborator

@v0idpwn v0idpwn commented Dec 30, 2024

Different from the previous fixes in #390, I'm not 100% sure about this one. Feels like it could/should be solved in a different layer, but I didn't find a better way to do it without breaking anything else.

test "map i32 i32" do
mod = ProtobufTestMessages.Proto2.TestAllTypesProto2
problematic_payload = <<194, 3, 0>>
assert m = %{map_int32_int32: %{0 => 0}} = mod.decode(problematic_payload)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without my change, the problematic map decodes to %{nil => nil} instead of %{0 => 0}, which is the desired behaviour.

Comment on lines 238 to 244
val =
if map?,
do: %{
(embedded_msg.key || map_default(prop, :key)) =>
embedded_msg.value || map_default(prop, :value)
},
else: embedded_msg
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit but we'll probably want a do/end here rather than the inline do:.

Also, is this gonna be fine with booleans?

@v0idpwn v0idpwn merged commit 2653f60 into main Jan 4, 2025
3 checks passed
@v0idpwn v0idpwn deleted the fix-conformance-tests-2 branch January 4, 2025 21:52
@v0idpwn v0idpwn mentioned this pull request Jan 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants