Prevent text in links from being double-escaped
This commit is contained in:
parent
272ca72d3d
commit
bd5ec792b7
|
@ -19,7 +19,8 @@ module SharedMarkers
|
|||
})
|
||||
end
|
||||
|
||||
content_tag(:a, text.nil? ? link : text, options)
|
||||
# Marking the text content as HTML safe as <tt>content_tag</tt> already escapes it for us
|
||||
content_tag(:a, text.nil? ? link : text.html_safe, options)
|
||||
rescue
|
||||
link
|
||||
end
|
||||
|
|
|
@ -22,6 +22,15 @@ describe MarkdownHelper, type: :helper do
|
|||
it "should transform mentions into links" do
|
||||
expect(markdown("@jake_weary")).to eq('<p><a href="/jake_weary">@jake_weary</a></p>')
|
||||
end
|
||||
|
||||
it "should escape text in links" do
|
||||
expect(markdown("[It's a link](https://example.com)")).to eq('<p><a href="/linkfilter?url=https%3A%2F%2Fexample.com" target="_blank" rel="nofollow">It\'s a link</a></p>')
|
||||
expect(markdown("[It's >a link](https://example.com)")).to eq('<p><a href="/linkfilter?url=https%3A%2F%2Fexample.com" target="_blank" rel="nofollow">It\'s >a link</a></p>')
|
||||
end
|
||||
|
||||
it "should escape HTML tags" do
|
||||
expect(markdown("I'm <h1>a test</h1>")).to eq("<p>I'm <h1>a test</h1></p>")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#strip_markdown" do
|
||||
|
|
Loading…
Reference in New Issue