From 00a7ea4de12da348bfb55159b1d3469d249c9a45 Mon Sep 17 00:00:00 2001 From: alusco-scratch <60235755+alusco-scratch@users.noreply.github.com> Date: Thu, 1 Oct 2020 21:20:31 -0700 Subject: [PATCH] Override Map.clone to use Map's dup method Message and Repeated field override clone so that it uses the internal implementation of dup but Map is missing this and only implements dup. This can lead to unexpected behavior since two out of three complex types behave correctly. --- ruby/ext/google/protobuf_c/map.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ruby/ext/google/protobuf_c/map.c b/ruby/ext/google/protobuf_c/map.c index 00d23a76fa30..2caffd086150 100644 --- a/ruby/ext/google/protobuf_c/map.c +++ b/ruby/ext/google/protobuf_c/map.c @@ -827,6 +827,8 @@ void Map_register(VALUE module) { rb_define_method(klass, "clear", Map_clear, 0); rb_define_method(klass, "length", Map_length, 0); rb_define_method(klass, "dup", Map_dup, 0); + // Also define #clone so that we don't inherit Object#clone. + rb_define_method(klass, "clone", Map_dup, 0); rb_define_method(klass, "==", Map_eq, 1); rb_define_method(klass, "hash", Map_hash, 0); rb_define_method(klass, "to_h", Map_to_h, 0);