Skip to content

Commit bb322c2

Browse files
committed
[Ruby] Fixed bug in string comparison logic.
1 parent fd8aabf commit bb322c2

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ruby/ext/google/protobuf_c/convert.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ bool Msgval_IsEqual(upb_msgval val1, upb_msgval val2, TypeInfo type_info) {
315315
return memcmp(&val1, &val2, 8) == 0;
316316
case UPB_TYPE_STRING:
317317
case UPB_TYPE_BYTES:
318-
return val1.str_val.size != val2.str_val.size ||
318+
return val1.str_val.size == val2.str_val.size &&
319319
memcmp(val1.str_val.data, val2.str_val.data,
320320
val1.str_val.size) == 0;
321321
case UPB_TYPE_MESSAGE:

ruby/tests/common_tests.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,18 @@ def test_map_basic
436436
end
437437
end
438438

439+
def test_b_8385
440+
m1 = Google::Protobuf::Map.new(:string, :string)
441+
m2 = Google::Protobuf::Map.new(:string, :string)
442+
443+
assert_equal m1, m2
444+
445+
m1["counter"] = "a"
446+
m2["counter"] = "aa"
447+
448+
assert_not_equal m1, m2
449+
end
450+
439451
def test_map_ctor
440452
m = Google::Protobuf::Map.new(:string, :int32,
441453
{"a" => 1, "b" => 2, "c" => 3})

0 commit comments

Comments
 (0)