Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/markdown_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def header(text, header_level)
end

def image(url, title, alt_text)
url, title, alt_text = [ url, title, alt_text ].map { ERB::Util.html_escape_once(it) }
%(<a title="#{title}" data-action="lightbox#open:prevent" data-lightbox-target="image" data-lightbox-url-value="#{url}?disposition=attachment" href="#{url}"><img src="#{url}" alt="#{alt_text}"></a>)
end

Expand Down
10 changes: 10 additions & 0 deletions test/lib/markdown_renderer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@ class MarkdownRendererTest < ActiveSupport::TestCase
assert_includes content, "id='duplicated-header'"
assert_includes content, "id='duplicated-header-2'"
end

test "it escapes image attributes" do
markdown = MarkdownRenderer.build
content = markdown.render(%(![a "b" &amp; c](/image.png?a=1&b=2 "x" data-x="y")))

assert_includes content, %(title="x&quot; data-x=&quot;y")
assert_includes content, %(alt="a &quot;b&quot; &amp; c")
assert_includes content, %(href="/image.png?a=1&amp;b=2")
assert_empty Nokogiri::HTML5.fragment(content).css("[data-x]")
end
end
Loading