@@ -665,6 +665,26 @@ def test_convert_RDOCLINK_ref
665665 assert_equal "\n <p>C</p>\n " , result
666666 end
667667
668+ def test_convert_RDOCLINK_escape_image
669+ assert_escaped '<script>' , 'rdoc-image:"><script>alert(`rdoc-image`)</script>"'
670+ end
671+
672+ def test_convert_RDOCLINK_escape_label_id
673+ assert_escaped '<script>' , 'rdoc-label::path::"><script>alert(`rdoc-label_id`)</script>"'
674+ end
675+
676+ def test_convert_RDOCLINK_escape_label_path
677+ assert_escaped '<script>' , 'rdoc-label::"><script>alert(`rdoc-label_path`)</script>"'
678+ end
679+
680+ def test_convert_RDOCLINK_escape_ref
681+ assert_escaped '<script>' , 'rdoc-ref:"><script>alert(`rdoc-ref`)</script>"'
682+ end
683+
684+ def test_convert_RDOCLINK_escape_xxx
685+ assert_escaped '<script>' , 'rdoc-xxx:"><script>alert(`rdoc-xxx`)</script>"'
686+ end
687+
668688 def test_convert_TIDYLINK_footnote
669689 result = @to . convert 'text{*1}[rdoc-label:foottext-1:footmark-1]'
670690
@@ -690,6 +710,11 @@ def test_convert_TIDYLINK_image
690710 "\n <p><a href=\" http://example.com\" ><img src=\" path/to/image.jpg\" ></a></p>\n "
691711
692712 assert_equal expected , result
713+
714+ result =
715+ @to . convert '{rdoc-image:<script>alert`link text`</script>}[http://example.com]'
716+
717+ assert_not_include result , "<script>"
693718 end
694719
695720 def test_convert_TIDYLINK_rdoc_label
@@ -704,6 +729,23 @@ def test_convert_TIDYLINK_irc
704729 assert_equal "\n <p><a href=\" irc://irc.freenode.net/#ruby-lang\" >ruby-lang</a></p>\n " , result
705730 end
706731
732+ def test_convert_TIDYLINK_escape_text
733+ assert_escaped '<script>' , '{<script>alert`link text`</script>}[a]'
734+ assert_escaped '<script>' , 'x:/<script>alert(1);</script>[[]'
735+ end
736+
737+ def test_convert_TIDYLINK_escape_javascript
738+ assert_not_include '{click}[javascript:alert`javascript_scheme`]' , '<a href="javascript:'
739+ end
740+
741+ def test_convert_TIDYLINK_escape_onmouseover
742+ assert_escaped '"/onmouseover="' , '{onmouseover}[http://"/onmouseover="alert`on_mouse_link`"]'
743+ end
744+
745+ def test_convert_TIDYLINK_escape_onerror
746+ assert_escaped '"onerror="' , '{link_image}[http://"onerror="alert`link_image`".png]'
747+ end
748+
707749 def test_convert_with_exclude_tag
708750 assert_equal "\n <p><code>aaa</code>[:symbol]</p>\n " , @to . convert ( '+aaa+[:symbol]' )
709751 assert_equal "\n <p><code>aaa[:symbol]</code></p>\n " , @to . convert ( '+aaa[:symbol]+' )
@@ -794,6 +836,11 @@ def test_handle_regexp_HYPERLINK_irc
794836 assert_equal '<a href="irc://irc.freenode.net/#ruby-lang">irc.freenode.net/#ruby-lang</a>' , link
795837 end
796838
839+ def test_handle_regexp_HYPERLINK_escape
840+ code = 'irc://irc.freenode.net/"><script>alert(`irc`)</script><a"'
841+ assert_escaped '<script>' , code
842+ end
843+
797844 def test_list_verbatim_2
798845 str = "* one\n verb1\n verb2\n * two\n "
799846
@@ -903,5 +950,11 @@ def test_accept_table
903950 assert_include ( res [ %r<<td[^<>]*>.*em.*</td>> ] , '<em>em</em>' )
904951 assert_include ( res [ %r<<td[^<>]*>.*strong.*</td>> ] , '<strong>strong</strong>' )
905952 end
953+
954+ def assert_escaped ( unexpected , code )
955+ result = @to . convert ( code )
956+ assert_not_include result , unexpected
957+ assert_include result , CGI . escapeHTML ( unexpected )
958+ end
906959end
907960
0 commit comments