A platform for community discussion. Free, open, simple.
FIX: Extract polls correctly when post contains multiple quotes (#36802)
Régis Hanola1a59b7ca6df
diff --git a/plugins/poll/lib/poll.rb b/plugins/poll/lib/poll.rbindex 8d53910adf0..ae32c7cc9c4 100644--- a/plugins/poll/lib/poll.rb+++ b/plugins/poll/lib/poll.rb@@ -425,12 +425,12 @@ class DiscoursePoll::Poll# TODO: we should fix the callback mess so that the cooked version is available# in the validators instead of cooking twice- raw = raw.sub(%r{\[quote.+/quote\]}m, "")cooked = PrettyText.cook(raw, topic_id: topic_id, user_id: user_id)Nokogiri.HTML5(cooked).css("div.poll")+ .reject { |p| p.ancestors("blockquote").any? }.map do |p|poll = { "options" => [], "name" => DiscoursePoll::DEFAULT_POLL_NAME }diff --git a/plugins/poll/spec/lib/poll_spec.rb b/plugins/poll/spec/lib/poll_spec.rbindex 5a6c907768f..bbda2032856 100644--- a/plugins/poll/spec/lib/poll_spec.rb+++ b/plugins/poll/spec/lib/poll_spec.rb@@ -337,6 +337,35 @@ RSpec.describe DiscoursePoll::Poll do},)end++ it "extracts poll when there are multiple quotes in the post" do+ raw = <<~RAW+ [quote="user1, post:1, topic:123"]+ First quote content+ [/quote]++ [poll type=regular results=always]+ * Option A+ * Option B+ [/poll]++ [quote="user2, post:2, topic:123"]+ Second quote content+ [/quote]++ Some text after.+ RAW++ polls = DiscoursePoll::Poll.extract(raw, 2)+ expect(polls.size).to eq(1)+ expect(polls.first["name"]).to eq("poll")+ expect(polls.first["type"]).to eq("regular")+ expect(polls.first["results"]).to eq("always")+ expect(polls.first["options"].map { |o| o["html"] }).to contain_exactly(+ "Option A",+ "Option B",+ )+ endenddescribe ".serialized_voters" do