Skip to content

A platform for community discussion. Free, open, simple.

FIX: Strip HTML from category og:description meta tag (#37322)

Samca3cdbb18cee
diff --git a/app/views/list/list.erb b/app/views/list/list.erb
index 92882fb3c5f..ce56aa71fe8 100644
--- a/app/views/list/list.erb
+++ b/app/views/list/list.erb
@@ -140,7 +140,7 @@
<% if @category %>
<% content_for :head do %>
<%= auto_discovery_link_tag(:rss, { action: :category_feed }, rel: 'alternate nofollow', title: t('rss_topics_in_category', category: @category.name)) %>
- <%= raw crawlable_meta_data(title: @category.name, description: @category.description, image: @category.uploaded_logo&.url.presence) %>
+ <%= raw crawlable_meta_data(title: @category.name, description: @category.description_text, image: @category.uploaded_logo&.url.presence) %>
<% end %>
<% elsif @tag_name %>
<% content_for :head do %>
diff --git a/spec/requests/list_controller_spec.rb b/spec/requests/list_controller_spec.rb
index c4dc8642ebd..e4f27f5364c 100644
--- a/spec/requests/list_controller_spec.rb
+++ b/spec/requests/list_controller_spec.rb
@@ -915,6 +915,28 @@ RSpec.describe ListController do
expect(response.body).to have_tag "title", text: "Amazing Category - Discourse"
end
+
+ it "renders og:description and twitter:description without HTML tags" do
+ amazing_category.update!(
+ description: "This is <strong>bold</strong> and <em>italic</em> text",
+ )
+ get "/c/#{amazing_category.slug}/#{amazing_category.id}"
+
+ expect(response.body).to have_tag(
+ :meta,
+ with: {
+ property: "og:description",
+ content: "This is bold and italic text",
+ },
+ )
+ expect(response.body).to have_tag(
+ :meta,
+ with: {
+ name: "twitter:description",
+ content: "This is bold and italic text",
+ },
+ )
+ end
end
context "for category latest view" do