Skip to content

Commit 8edc744

Browse files
authored
Fix poll options not being stripped of surrounding whitespace on save (mastodon#10168)
1 parent f0a1637 commit 8edc744

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

app/models/poll.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,11 @@ class Poll < ApplicationRecord
3232
scope :attached, -> { where.not(status_id: nil) }
3333
scope :unattached, -> { where(status_id: nil) }
3434

35+
before_validation :prepare_options
3536
before_validation :prepare_votes_count
37+
3638
after_initialize :prepare_cached_tallies
39+
3740
after_commit :reset_parent_cache, on: :update
3841

3942
def loaded_options
@@ -75,6 +78,10 @@ def prepare_votes_count
7578
self.votes_count = cached_tallies.sum unless cached_tallies.empty?
7679
end
7780

81+
def prepare_options
82+
self.options = options.map(&:strip).reject(&:blank?)
83+
end
84+
7885
def reset_parent_cache
7986
return if status_id.nil?
8087
Rails.cache.delete("statuses/#{status_id}")

0 commit comments

Comments
 (0)