From 99e9e4fd3fac26b4c057965b162685c323f25264 Mon Sep 17 00:00:00 2001 From: Santiago Rodriguez <46354312+santiagorodriguez96@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:31:51 -0300 Subject: [PATCH] fix: do not add the key to the hash if its value is `nil` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In Rails, `nil` responds to `as_json` therefore the attributes whose value is `nil` are added to the result of `as_json`, which may end up causing issues with some authenticators – see https://github.com/cedarcode/webauthn-ruby/issues/441. This commits adds another condition to the if in order to prevent this from happening. --- lib/webauthn/json_serializer.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/webauthn/json_serializer.rb b/lib/webauthn/json_serializer.rb index 124d5dd1..f65159e5 100644 --- a/lib/webauthn/json_serializer.rb +++ b/lib/webauthn/json_serializer.rb @@ -13,7 +13,7 @@ def to_hash_with_camelized_keys attributes.each_with_object({}) do |attribute_name, hash| value = send(attribute_name) - if value.respond_to?(:as_json) + if value && value.respond_to?(:as_json) hash[camelize(attribute_name)] = value.as_json elsif value hash[camelize(attribute_name)] = deep_camelize_keys(value)