Skip to content

Commit 47c715e

Browse files
ivantseppdwradcliffe
authored andcommitted
Sanitize Rdoc output
Signed-off-by: David Radcliffe <radcliffe.david@gmail.com>
1 parent 711751e commit 47c715e

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

app/helpers/rubygems_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def simple_markup(text)
2525
if text =~ /^==+ [A-Z]/
2626
options = RDoc::Options.new
2727
options.pipe = true
28-
RDoc::Markup.new.convert(text, RDoc::Markup::ToHtml.new(options)).html_safe
28+
sanitize RDoc::Markup.new.convert(text, RDoc::Markup::ToHtml.new(options))
2929
else
3030
content_tag :p, escape_once(sanitize(text.strip)), nil, false
3131
end

test/unit/helpers/rubygems_helper_test.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,14 @@ class RubygemsHelperTest < ActionView::TestCase
144144

145145
should 'work on rdoc strings' do
146146
text = '== FOO'
147-
assert_equal "\n<h2 id=\"label-FOO\">FOO</h2>\n", simple_markup(text)
147+
assert_equal "\n<h2>FOO</h2>\n", simple_markup(text)
148+
assert simple_markup(text).html_safe?
149+
end
150+
151+
should 'sanitize rdoc strings' do
152+
text = "== FOO\nclick[javascript:alert('foo')]"
153+
assert_equal "\n<h2>FOO</h2>\n\n<p><a>click</a></p>\n", simple_markup(text)
154+
148155
assert simple_markup(text).html_safe?
149156
end
150157
end

0 commit comments

Comments
 (0)