Prevent Twitter markdown from stripping `<///3`

This commit is contained in:
Karina Kwiatek 2022-07-30 19:41:47 +02:00
parent 3f23385ba7
commit afa1a102d6
2 changed files with 6 additions and 2 deletions

View File

@ -7,12 +7,12 @@ module MarkdownHelper
def strip_markdown(content) def strip_markdown(content)
md = Redcarpet::Markdown.new(Redcarpet::Render::StripDown, MARKDOWN_OPTS) md = Redcarpet::Markdown.new(Redcarpet::Render::StripDown, MARKDOWN_OPTS)
CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip CGI.unescape_html(Sanitize.fragment(CGI.escape_html(md.render(content)), EVIL_TAGS)).strip
end end
def twitter_markdown(content) def twitter_markdown(content)
md = Redcarpet::Markdown.new(TwitteredMarkdown, MARKDOWN_OPTS) md = Redcarpet::Markdown.new(TwitteredMarkdown, MARKDOWN_OPTS)
CGI.unescape_html(Sanitize.fragment(md.render(content), EVIL_TAGS)).strip CGI.unescape_html(Sanitize.fragment(CGI.escape_html(md.render(content)), EVIL_TAGS)).strip
end end
def question_markdown(content) def question_markdown(content)

View File

@ -59,6 +59,10 @@ describe MarkdownHelper, type: :helper do
expect(twitter_markdown("@test")).to eq("test") expect(twitter_markdown("@test")).to eq("test")
end end
end end
it "should not strip weird hearts" do
expect(twitter_markdown("<///3")).to eq("<///3")
end
end end
describe "#question_markdown" do describe "#question_markdown" do