Merge pull request #594 from Retrospring/</3

Prevent Twitter markdown from stripping `<///3`
This commit is contained in:
Karina Kwiatek 2022-07-30 19:48:03 +02:00 committed by GitHub
commit a87a06e69f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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