]> cat aescling's git repositories - mastodon.git/commitdiff
Fix poll options not being stripped of surrounding whitespace on save (#10168)
authorEugen Rochko <eugen@zeonfederated.com>
Tue, 5 Mar 2019 02:45:56 +0000 (03:45 +0100)
committerGitHub <noreply@github.com>
Tue, 5 Mar 2019 02:45:56 +0000 (03:45 +0100)
app/models/poll.rb

index ba0b17f91948baf97e1da393cca4095f9279107b..ab7236d455f9ab081b7f11b50e2d7b31b88bb644 100644 (file)
@@ -32,8 +32,11 @@ class Poll < ApplicationRecord
   scope :attached, -> { where.not(status_id: nil) }
   scope :unattached, -> { where(status_id: nil) }
 
+  before_validation :prepare_options
   before_validation :prepare_votes_count
+
   after_initialize :prepare_cached_tallies
+
   after_commit :reset_parent_cache, on: :update
 
   def loaded_options
@@ -75,6 +78,10 @@ class Poll < ApplicationRecord
     self.votes_count = cached_tallies.sum unless cached_tallies.empty?
   end
 
+  def prepare_options
+    self.options = options.map(&:strip).reject(&:blank?)
+  end
+
   def reset_parent_cache
     return if status_id.nil?
     Rails.cache.delete("statuses/#{status_id}")