1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/rdoc] Escape method names in HTML

The following is invalid HTML:
<a href="Array.html#method-i-3C-3C"><code><<</code></a></p>

Incorrect:
<code><<</code>

Correct:
<code>&lt;&lt;</code>

Fixes #761

https://github.com/ruby/rdoc/commit/b120d087f6
This commit is contained in:
Nate Matykiewicz 2020-04-04 23:20:22 -05:00 committed by aycabta
parent b10c9d2012
commit c79f9ea606
2 changed files with 15 additions and 1 deletions

View file

@ -144,7 +144,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml
path = ref.as_href @from_path
if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
text = "<code>#{text}</code>"
text = "<code>#{CGI.escapeHTML text}</code>"
end
if path =~ /#/ then

View file

@ -89,6 +89,20 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase
assert_equal para("<a href=\"C1.html#method-c-25\"><code>C1::%</code></a>"), result
end
def test_convert_RDOCLINK_rdoc_ref_method_escape_html
m = @c1.add_method RDoc::AnyMethod.new nil, '<<'
m.singleton = false
result = @to.convert 'rdoc-ref:C1#<<'
assert_equal para("<a href=\"C1.html#method-i-3C-3C\"><code>C1#&lt;&lt;</code></a>"), result
m.singleton = true
result = @to.convert 'rdoc-ref:C1::<<'
assert_equal para("<a href=\"C1.html#method-c-3C-3C\"><code>C1::&lt;&lt;</code></a>"), result
end
def test_convert_RDOCLINK_rdoc_ref_method_percent_label
m = @c1.add_method RDoc::AnyMethod.new nil, '%'
m.singleton = false