diff --git a/lib/rdoc/markup/to_html.rb b/lib/rdoc/markup/to_html.rb
index 3c4f82f748..ccafdb61ba 100644
--- a/lib/rdoc/markup/to_html.rb
+++ b/lib/rdoc/markup/to_html.rb
@@ -84,7 +84,7 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
def handle_RDOCLINK url # :nodoc:
case url
when /^rdoc-ref:/
- $'
+ CGI.escapeHTML($')
when /^rdoc-label:/
text = $'
@@ -95,13 +95,11 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
else text
end
- gen_url url, text
+ gen_url CGI.escapeHTML(url), CGI.escapeHTML(text)
when /^rdoc-image:/
- ""
- else
- url =~ /\Ardoc-[a-z]+:/
-
- $'
+ %[
]
+ when /\Ardoc-[a-z]+:/
+ CGI.escapeHTML($')
end
end
diff --git a/test/rdoc/test_rdoc_markup_to_html.rb b/test/rdoc/test_rdoc_markup_to_html.rb
index 8a38694c45..3e4a8e8915 100644
--- a/test/rdoc/test_rdoc_markup_to_html.rb
+++ b/test/rdoc/test_rdoc_markup_to_html.rb
@@ -665,6 +665,26 @@ EXPECTED
assert_equal "\n
C
\n", result end + def test_convert_RDOCLINK_escape_image + assert_escaped '"' + end + + def test_convert_RDOCLINK_escape_label_id + assert_escaped '"' + end + + def test_convert_RDOCLINK_escape_label_path + assert_escaped '"' + end + + def test_convert_RDOCLINK_escape_ref + assert_escaped '"' + end + + def test_convert_RDOCLINK_escape_xxx + assert_escaped '"' + end + def test_convert_TIDYLINK_footnote result = @to.convert 'text{*1}[rdoc-label:foottext-1:footmark-1]' @@ -690,6 +710,11 @@ EXPECTED "\n\n" assert_equal expected, result + + result = + @to.convert '{rdoc-image:}[http://example.com]' + + assert_not_include result, "