瀏覽代碼

[Ruby] Fixed bug in string comparison logic.

Joshua Haberman 4 年之前
父節點
當前提交
bb322c2b39
共有 2 個文件被更改,包括 13 次插入1 次删除
  1. 1 1
      ruby/ext/google/protobuf_c/convert.c
  2. 12 0
      ruby/tests/common_tests.rb

+ 1 - 1
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:

+ 12 - 0
ruby/tests/common_tests.rb

@@ -436,6 +436,18 @@ module CommonTests
     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})