Skip to content

Commit c0ad153

Browse files
authored
Merge pull request #528 from aycabta/escape-yield-parameters
Escape yield parameters
2 parents 88db33d + 5289140 commit c0ad153

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

lib/rdoc/generator/template/darkfish/class.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<% else %>
115115
<div class="method-heading">
116116
<span class="method-name"><%= h method.name %></span><span
117-
class="method-args"><%= method.param_seq %></span>
117+
class="method-args"><%= h method.param_seq %></span>
118118
<% if method.token_stream then %>
119119
<span class="method-click-advice">click to toggle source</span>
120120
<% end %>

test/test_rdoc_generator_darkfish.rb

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ def setup
4343

4444
@meth = RDoc::AnyMethod.new nil, 'method'
4545
@meth_bang = RDoc::AnyMethod.new nil, 'method!'
46+
@meth_with_html_tag_yield = RDoc::AnyMethod.new nil, 'method_with_html_tag_yield'
47+
@meth_with_html_tag_yield.block_params = '%<<script>alert("atui")</script>>, yield_arg'
4648
@attr = RDoc::Attr.new nil, 'attr', 'RW', ''
4749

4850
@klass.add_method @meth
4951
@klass.add_method @meth_bang
52+
@klass.add_method @meth_with_html_tag_yield
5053
@klass.add_attribute @attr
5154

5255
@ignored = @top_level.add_class RDoc::NormalClass, 'Ignored'
@@ -167,7 +170,7 @@ def test_setup
167170
assert_equal [@klass_alias, @ignored, @klass, @object],
168171
@g.classes.sort_by { |klass| klass.full_name }
169172
assert_equal [@top_level], @g.files
170-
assert_equal [@meth, @meth, @meth_bang, @meth_bang], @g.methods
173+
assert_equal [@meth, @meth, @meth_bang, @meth_bang, @meth_with_html_tag_yield, @meth_with_html_tag_yield], @g.methods
171174
assert_equal [@klass_alias, @klass, @object], @g.modsort
172175
end
173176

@@ -199,6 +202,23 @@ def test_template_for_partial
199202
assert_same template, @g.send(:template_for, partial)
200203
end
201204

205+
def test_generated_method_with_html_tag_yield
206+
top_level = @store.add_file 'file.rb'
207+
top_level.add_class @klass.class, @klass.name
208+
209+
@g.generate
210+
211+
path = File.join @tmpdir, 'A.html'
212+
213+
f = open(path)
214+
internal_file = f.read
215+
method_name_index = internal_file.index('<span class="method-name">method_with_html_tag_yield</span>')
216+
last_of_method_name_index = method_name_index + internal_file[method_name_index..-1].index('<div class="method-description">') - 1
217+
method_name = internal_file[method_name_index..last_of_method_name_index]
218+
219+
assert_includes method_name, '{ |%&lt;&lt;script&gt;alert(&quot;atui&quot;)&lt;/script&gt;&gt;, yield_arg| ... }'
220+
end
221+
202222
##
203223
# Asserts that +filename+ has a link count greater than 1 if hard links to
204224
# @tmpdir are supported.

0 commit comments

Comments
 (0)