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
4 changes: 2 additions & 2 deletions lib/rdoc/markup/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,15 @@ def accept_table header, body, aligns
header.zip(aligns) do |text, align|
@res << '<th'
@res << ' align="' << align << '"' if align
@res << '>' << CGI.escapeHTML(text) << "</th>\n"
@res << '>' << to_html(text) << "</th>\n"
end
@res << "</tr>\n</thead>\n<tbody>\n"
body.each do |row|
@res << "<tr>\n"
row.zip(aligns) do |text, align|
@res << '<td'
@res << ' align="' << align << '"' if align
@res << '>' << CGI.escapeHTML(text) << "</td>\n"
@res << '>' << to_html(text) << "</td>\n"
end
@res << "</tr>\n"
end
Expand Down
27 changes: 27 additions & 0 deletions test/rdoc/test_rdoc_markup_to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -876,5 +876,32 @@ def util_format text
@to.end_accepting
end

def test_accept_table
header = %w[Col1 Col2 Col3]
body = [
%w[cell1_1 cell1_2 cell1_3],
%w[cell2_1 cell2_2 cell2_3],
['<script>alert("foo");</script>',],
%w[+code+ _em_ **strong**],
]
aligns = [:left, :right, nil]
@to.start_accepting
@to.accept_table(header, body, aligns)
res = @to.end_accepting
assert_include(res[%r<<th[^<>]*>Col1</th>>], 'align="left"')
assert_include(res[%r<<th[^<>]*>Col2</th>>], 'align="right"')
assert_not_include(res[%r<<th[^<>]*>Col3</th>>], 'align=')
assert_include(res[%r<<td[^<>]*>cell1_1</td>>], 'align="left"')
assert_include(res[%r<<td[^<>]*>cell1_2</td>>], 'align="right"')
assert_not_include(res[%r<<td[^<>]*>cell1_3</td>>], 'align=')
assert_include(res[%r<<td[^<>]*>cell2_1</td>>], 'align="left"')
assert_include(res[%r<<td[^<>]*>cell2_2</td>>], 'align="right"')
assert_not_include(res[%r<<td[^<>]*>cell2_3</td>>], 'align=')
assert_not_include(res, '<script>')
assert_include(res[%r<<td[^<>]*>.*script.*</td>>], '&lt;script&gt;')
assert_include(res[%r<<td[^<>]*>.*code.*</td>>], '<code>code</code>')
assert_include(res[%r<<td[^<>]*>.*em.*</td>>], '<em>em</em>')
assert_include(res[%r<<td[^<>]*>.*strong.*</td>>], '<strong>strong</strong>')
end
end