FIX: reduce poll when post is nil

FIX: reduce poll when post is nil

diff --git a/plugins/poll/plugin.rb b/plugins/poll/plugin.rb
index 4a494cf..c1fdd15 100644
--- a/plugins/poll/plugin.rb
+++ b/plugins/poll/plugin.rb
@@ -437,8 +437,13 @@ after_initialize do
 
   on(:reduce_excerpt) do |doc, options|
     post = options[:post]
+
+    replacement = post ?
+      "<a href='#{UrlHelper.escape_uri(post.url)}'>#{I18n.t("poll.poll")}</a>" :
+      "#{I18n.t("poll.poll")}"
+
     doc.css("div.poll").each do |poll|
-      poll.replace "<a href='#{UrlHelper.escape_uri(post.url)}'>#{I18n.t("poll.poll")}</a>"
+      poll.replace(replacement)
     end
   end

GitHub sha: a188d15b

This commit has been mentioned on Discourse Meta. There might be relevant details there:

Is there a test we can add for this?

Looks like this is related to

https://review.discourse.org/t/feature-implement-onebox-for-posts-including-polls-7539/3925/4

1 Like

I’ve added a test here:

1 Like