From 80ca4fdb3c6fb23d20213b075ccf59106e0e3129 Mon Sep 17 00:00:00 2001 From: Claire Date: Wed, 11 Aug 2021 16:40:55 +0200 Subject: [PATCH] Fix crash when encountering invalid account fields (#16598) * Add test * Fix crash when encountering invalid account fields --- app/models/account.rb | 6 +++++- spec/services/activitypub/process_account_service_spec.rb | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/account.rb b/app/models/account.rb index 007adc409bcf87..089727529a87c9 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -302,7 +302,11 @@ def also_known_as end def fields - (self[:fields] || []).map { |f| Field.new(self, f) } + (self[:fields] || []).map do |f| + Field.new(self, f) + rescue + nil + end.compact end def fields_attributes=(attributes) diff --git a/spec/services/activitypub/process_account_service_spec.rb b/spec/services/activitypub/process_account_service_spec.rb index 56e7f83211b4e0..1b1d878a7e6b30 100644 --- a/spec/services/activitypub/process_account_service_spec.rb +++ b/spec/services/activitypub/process_account_service_spec.rb @@ -12,6 +12,7 @@ attachment: [ { type: 'PropertyValue', name: 'Pronouns', value: 'They/them' }, { type: 'PropertyValue', name: 'Occupation', value: 'Unit test' }, + { type: 'PropertyValue', name: 'non-string', value: ['foo', 'bar'] }, ], }.with_indifferent_access end