Skip to content

Commit

Permalink
fix: do not add the key to the hash if its value is nil
Browse files Browse the repository at this point in the history
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 #441.

This commits adds another condition to the if in order to prevent
this from happening.
  • Loading branch information
santiagorodriguez96 committed Nov 14, 2024
1 parent 0230ccc commit 99e9e4f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/webauthn/json_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 99e9e4f

Please sign in to comment.