From 89c4f80523fd85a6aca18256153e92b492c1561b Mon Sep 17 00:00:00 2001 From: johnnyshields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 8 May 2025 00:19:56 +0900 Subject: [PATCH 1/2] Hash should honor BSON::Registry --- lib/bson/hash.rb | 8 +++++++- lib/bson/registry.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/bson/hash.rb b/lib/bson/hash.rb index 197349cc5..604e63276 100644 --- a/lib/bson/hash.rb +++ b/lib/bson/hash.rb @@ -167,7 +167,7 @@ def maybe_dbref(hash) # # @return [ Hash ] the hash parsed from the buffer def parse_hash_from_buffer(buffer, **options) - hash = Document.allocate + hash = ruby_base_type.allocate start_position = buffer.read_position expected_byte_size = buffer.get_int32 @@ -200,6 +200,12 @@ def parse_hash_contents(hash, buffer, **options) hash.store(field, value) end end + + private + + def ruby_base_type + BSON::Registry.get(BSON_TYPE) + end end # Register this type when the module is loaded. diff --git a/lib/bson/registry.rb b/lib/bson/registry.rb index 047df9a5b..beb25cdb8 100644 --- a/lib/bson/registry.rb +++ b/lib/bson/registry.rb @@ -42,7 +42,7 @@ module Registry # # @since 2.0.0 def get(byte, field = nil) - if type = MAPPINGS[byte] || (byte.is_a?(String) && type = MAPPINGS[byte.ord]) + if (type = MAPPINGS[byte]) || (byte.is_a?(String) && (type = MAPPINGS[byte.ord])) type else handle_unsupported_type!(byte, field) From d99b9654de573936756dabf2083482bad082e5e9 Mon Sep 17 00:00:00 2001 From: Johnny Shields <27655+johnnyshields@users.noreply.github.com> Date: Thu, 8 May 2025 09:36:25 +0900 Subject: [PATCH 2/2] Update hash.rb --- lib/bson/hash.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/bson/hash.rb b/lib/bson/hash.rb index 604e63276..4bd7adf29 100644 --- a/lib/bson/hash.rb +++ b/lib/bson/hash.rb @@ -201,8 +201,6 @@ def parse_hash_contents(hash, buffer, **options) end end - private - def ruby_base_type BSON::Registry.get(BSON_TYPE) end