Skip to content

Commit

Permalink
Fixed message equality in cases where the message type is different.
Browse files Browse the repository at this point in the history
If the message types are different, equality comparison must return
false.
  • Loading branch information
haberman committed Mar 30, 2021
1 parent fd8aabf commit d69f482
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ruby/ext/google/protobuf_c/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ static VALUE Message_eq(VALUE _self, VALUE _other) {
Message* self = ruby_to_Message(_self);
Message* other = ruby_to_Message(_other);

return Message_Equal(self->msg, other->msg, self->msgdef)
return self->msgdef == other->msgdef &&
Message_Equal(self->msg, other->msg, self->msgdef)
? Qtrue
: Qfalse;
}
Expand Down
3 changes: 2 additions & 1 deletion ruby/tests/common_tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,13 @@ def test_deep_copy
assert m.repeated_msg[0].object_id != m2.repeated_msg[0].object_id
end

def test_eq
def test_message_eq
m = proto_module::TestMessage.new(:optional_int32 => 42,
:repeated_int32 => [1, 2, 3])
m2 = proto_module::TestMessage.new(:optional_int32 => 43,
:repeated_int32 => [1, 2, 3])
assert m != m2
assert_not_equal proto_module::TestMessage.new, proto_module::TestMessage2.new
end

def test_enum_lookup
Expand Down

0 comments on commit d69f482

Please sign in to comment.