Fix crash when encountering invalid account fields (#16598)

* Add test

* Fix crash when encountering invalid account fields
pull/16510/head
Claire 2021-08-11 16:40:55 +02:00 committed by GitHub
parent 229f5d1681
commit 13b08610a0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -295,7 +295,11 @@ class Account < ApplicationRecord
end end
def fields def fields
(self[:fields] || []).map { |f| Field.new(self, f) } (self[:fields] || []).map do |f|
Field.new(self, f)
rescue
nil
end.compact
end end
def fields_attributes=(attributes) def fields_attributes=(attributes)

View File

@ -12,6 +12,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
attachment: [ attachment: [
{ type: 'PropertyValue', name: 'Pronouns', value: 'They/them' }, { type: 'PropertyValue', name: 'Pronouns', value: 'They/them' },
{ type: 'PropertyValue', name: 'Occupation', value: 'Unit test' }, { type: 'PropertyValue', name: 'Occupation', value: 'Unit test' },
{ type: 'PropertyValue', name: 'non-string', value: ['foo', 'bar'] },
], ],
}.with_indifferent_access }.with_indifferent_access
end end