Skip to content

Commit b120d08

Browse files
natematykiewiczioquatix
authored andcommitted
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
1 parent 0ead786 commit b120d08

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/rdoc/markup/to_html_crossref.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def link name, text, code = true
144144
path = ref.as_href @from_path
145145

146146
if code and RDoc::CodeObject === ref and !(RDoc::TopLevel === ref)
147-
text = "<code>#{text}</code>"
147+
text = "<code>#{CGI.escapeHTML text}</code>"
148148
end
149149

150150
if path =~ /#/ then

test/rdoc/test_rdoc_markup_to_html_crossref.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,20 @@ def test_convert_RDOCLINK_rdoc_ref_method_percent
8989
assert_equal para("<a href=\"C1.html#method-c-25\"><code>C1::%</code></a>"), result
9090
end
9191

92+
def test_convert_RDOCLINK_rdoc_ref_method_escape_html
93+
m = @c1.add_method RDoc::AnyMethod.new nil, '<<'
94+
m.singleton = false
95+
96+
result = @to.convert 'rdoc-ref:C1#<<'
97+
98+
assert_equal para("<a href=\"C1.html#method-i-3C-3C\"><code>C1#&lt;&lt;</code></a>"), result
99+
m.singleton = true
100+
101+
result = @to.convert 'rdoc-ref:C1::<<'
102+
103+
assert_equal para("<a href=\"C1.html#method-c-3C-3C\"><code>C1::&lt;&lt;</code></a>"), result
104+
end
105+
92106
def test_convert_RDOCLINK_rdoc_ref_method_percent_label
93107
m = @c1.add_method RDoc::AnyMethod.new nil, '%'
94108
m.singleton = false

0 commit comments

Comments
 (0)