]> cat aescling's git repositories - mastodon.git/commitdiff
Fix crash when encountering invalid account fields (#16598)
authorClaire <claire.github-309c@sitedethib.com>
Wed, 11 Aug 2021 14:40:55 +0000 (16:40 +0200)
committerGitHub <noreply@github.com>
Wed, 11 Aug 2021 14:40:55 +0000 (16:40 +0200)
* Add test

* Fix crash when encountering invalid account fields

app/models/account.rb
spec/services/activitypub/process_account_service_spec.rb

index a6d8d15374469366040d29b2599b5329e62d0834..f7a7f4a7b442853c03cb1d6a5536891f7a6d74b6 100644 (file)
@@ -295,7 +295,11 @@ class Account < ApplicationRecord
   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)
index 56e7f83211b4e069ebb896dec0d79d42a9eaae3b..1b1d878a7e6b3018c2d1db554e26cd73c5d39c0f 100644 (file)
@@ -12,6 +12,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
         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