[前][次][番号順一覧][スレッド一覧]

ruby-changes:61359

From: Nate <ko1@a...>
Date: Sun, 24 May 2020 23:52:58 +0900 (JST)
Subject: [ruby-changes:61359] c79f9ea606 (master): [ruby/rdoc] Escape method names in HTML

https://git.ruby-lang.org/ruby.git/commit/?id=c79f9ea606

From c79f9ea606d072176533b22813653f9fd26940af Mon Sep 17 00:00:00 2001
From: Nate Matykiewicz <natematykiewicz@g...>
Date: Sat, 4 Apr 2020 23:20:22 -0500
Subject: [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

diff --git a/lib/rdoc/markup/to_html_crossref.rb b/lib/rdoc/markup/to_html_crossref.rb
index 9314f04..4a3f028 100644
--- a/lib/rdoc/markup/to_html_crossref.rb
+++ b/lib/rdoc/markup/to_html_crossref.rb
@@ -144,7 +144,7 @@ class RDoc::Markup::ToHtmlCrossref < RDoc::Markup::ToHtml https://github.com/ruby/ruby/blob/trunk/lib/rdoc/markup/to_html_crossref.rb#L144
       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
diff --git a/test/rdoc/test_rdoc_markup_to_html_crossref.rb b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
index bac2569..70306c6 100644
--- a/test/rdoc/test_rdoc_markup_to_html_crossref.rb
+++ b/test/rdoc/test_rdoc_markup_to_html_crossref.rb
@@ -89,6 +89,20 @@ class TestRDocMarkupToHtmlCrossref < XrefTestCase https://github.com/ruby/ruby/blob/trunk/test/rdoc/test_rdoc_markup_to_html_crossref.rb#L89
     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
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]