A platform for community discussion. Free, open, simple.
FIX: don't validate and render the polls inside a quoted post. (#15019)
Vinoth Kannan461936f2112e
diff --git a/plugins/poll/assets/javascripts/initializers/extend-for-poll.js b/plugins/poll/assets/javascripts/initializers/extend-for-poll.jsindex e1808664b51..4010611563f 100644--- a/plugins/poll/assets/javascripts/initializers/extend-for-poll.js+++ b/plugins/poll/assets/javascripts/initializers/extend-for-poll.js@@ -71,7 +71,10 @@ function initializePolls(api) {});function attachPolls(elem, helper) {- const pollNodes = elem.querySelectorAll(".poll");+ let pollNodes = [...elem.querySelectorAll(".poll")];+ pollNodes = pollNodes.filter(+ (node) => node.parentNode.tagName !== "BLOCKQUOTE"+ );if (!pollNodes.length || !helper) {return;}diff --git a/plugins/poll/lib/poll.rb b/plugins/poll/lib/poll.rbindex 0e9c28ef3fe..1e5df985f27 100644--- a/plugins/poll/lib/poll.rb+++ b/plugins/poll/lib/poll.rb@@ -286,6 +286,7 @@ class DiscoursePoll::Polldef self.extract(raw, topic_id, user_id = nil)# TODO: we should fix the callback mess so that the cooked version is available# in the validators instead of cooking twice+ raw = raw.sub(/\[quote.+\/quote\]/m, '')cooked = PrettyText.cook(raw, topic_id: topic_id, user_id: user_id)Nokogiri::HTML5(cooked).css("div.poll").map do |p|diff --git a/plugins/poll/spec/lib/poll_spec.rb b/plugins/poll/spec/lib/poll_spec.rbindex 11c35adbb71..289cccf19dd 100644--- a/plugins/poll/spec/lib/poll_spec.rb+++ b/plugins/poll/spec/lib/poll_spec.rb@@ -211,4 +211,37 @@ describe DiscoursePoll::Poll doexpect(messages.count).to eq(0)endend++ describe '.extract' do+ it "skips the polls inside quote" do+ raw = <<~RAW+ [quote="username, post:1, topic:2"]+ [poll type=regular result=always]+ * 1+ * 2+ [/poll]+ [/quote]++ [poll type=regular result=always]+ * 3+ * 4+ [/poll]++ Post with a poll and a quoted poll.+ RAW++ expect(DiscoursePoll::Poll.extract(raw, 2)).to contain_exactly({+ "name" => "poll",+ "options" => [{+ "html" => "3",+ "id" => "68b434ff88aeae7054e42cd05a4d9056"+ }, {+ "html" => "4",+ "id" => "aa2393b424f2f395abb63bf785760a3b"+ }],+ "status" => "open",+ "type" => "regular"+ })+ end+ endend