]> cat aescling's git repositories - mastodon.git/commitdiff
Fix empty poll options not being filtered on remote poll update (#12484)
authorThibG <thib@sitedethib.com>
Tue, 26 Nov 2019 21:46:31 +0000 (22:46 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 26 Nov 2019 21:46:31 +0000 (22:46 +0100)
If a poll contains empty options (which is apparently possible on Pleroma),
it is created without them. However, the poll update code doesn't filter
empty options, and thus:
1. Clear known votes, as it assumes the set of options has changed
2. Errors out because it tries adding empty options, which fails validation

This commit fixes that by filtering them out the same way they are filtered
out at poll creation time.

app/services/activitypub/process_poll_service.rb

index cb4a0d46025a82153142860d7c3b87edeb3353a8..903b6a78adf5327ec7ceda21cc221f6624696c5e 100644 (file)
@@ -30,7 +30,7 @@ class ActivityPub::ProcessPollService < BaseService
 
     voters_count = @json['votersCount']
 
-    latest_options = items.map { |item| item['name'].presence || item['content'] }
+    latest_options = items.map { |item| item['name'].presence || item['content'] }.compact
 
     # If for some reasons the options were changed, it invalidates all previous
     # votes, so we need to remove them