From bb322c2b39c1a98f78a5a433afe7a33cbae379a6 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Fri, 5 Mar 2021 08:23:42 -0800 Subject: [PATCH] [Ruby] Fixed bug in string comparison logic. --- ruby/ext/google/protobuf_c/convert.c | 2 +- ruby/tests/common_tests.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ruby/ext/google/protobuf_c/convert.c b/ruby/ext/google/protobuf_c/convert.c index bc3e35a5ed26..2fddc096291b 100644 --- a/ruby/ext/google/protobuf_c/convert.c +++ b/ruby/ext/google/protobuf_c/convert.c @@ -315,7 +315,7 @@ bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info) { return memcmp(&val1, &val2, 8) == 0; case UPB_TYPE_STRING: case UPB_TYPE_BYTES: - return val1.str_val.size != val2.str_val.size || + return val1.str_val.size == val2.str_val.size && memcmp(val1.str_val.data, val2.str_val.data, val1.str_val.size) == 0; case UPB_TYPE_MESSAGE: diff --git a/ruby/tests/common_tests.rb b/ruby/tests/common_tests.rb index 1957422fa937..40c7726d8321 100644 --- a/ruby/tests/common_tests.rb +++ b/ruby/tests/common_tests.rb @@ -436,6 +436,18 @@ def test_map_basic end end + def test_b_8385 + m1 = Google::Protobuf::Map.new(:string, :string) + m2 = Google::Protobuf::Map.new(:string, :string) + + assert_equal m1, m2 + + m1["counter"] = "a" + m2["counter"] = "aa" + + assert_not_equal m1, m2 + end + def test_map_ctor m = Google::Protobuf::Map.new(:string, :int32, {"a" => 1, "b" => 2, "c" => 3})