Skip to content

Commit d48213c

Browse files
committed
added decidated scrubber for post titles
1 parent 8f9e32f commit d48213c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

app/helpers/posts_helper.rb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def post_user_link(post, active: false)
1313
# @return [ActiveSupport::SafeBuffer] rendered title
1414
def rendered_title(post)
1515
raw_title = post.top_level? ? post.title : post.parent.title
16-
sanitize(render_markdown(raw_title))
16+
sanitize(render_markdown(raw_title), scrubber: title_scrubber)
1717
end
1818

1919
##
@@ -84,6 +84,22 @@ def max_title_length(_category)
8484
[SiteSetting['MaxTitleLength'] || 255, 255].min
8585
end
8686

87+
class PostTitleScrubber < Rails::HTML::PermitScrubber
88+
ALLOWED_ATTRS = %w[].freeze
89+
90+
ALLOWED_TAGS = %w[code em strong strike del sup sub kbd].freeze
91+
92+
def initialize
93+
super
94+
self.tags = ALLOWED_TAGS
95+
self.attributes = ALLOWED_ATTRS
96+
end
97+
98+
def skip_node?(node)
99+
node.text?
100+
end
101+
end
102+
87103
class PostScrubber < Rails::Html::PermitScrubber
88104
ALLOWED_ATTRS = %w[id class href title src height width alt rowspan colspan lang start dir].freeze
89105

@@ -108,4 +124,10 @@ def skip_node?(node)
108124
def scrubber
109125
PostsHelper::PostScrubber.new
110126
end
127+
128+
# Get a post title scrubber instance
129+
# @return [PostTitleScrubber]
130+
def title_scrubber
131+
PostsHelper::PostTitleScrubber.new
132+
end
111133
end

0 commit comments

Comments
 (0)