@@ -665,6 +665,26 @@ def test_convert_RDOCLINK_ref
665
665
assert_equal "\n <p>C</p>\n " , result
666
666
end
667
667
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
+
668
688
def test_convert_TIDYLINK_footnote
669
689
result = @to . convert 'text{*1}[rdoc-label:foottext-1:footmark-1]'
670
690
@@ -690,6 +710,11 @@ def test_convert_TIDYLINK_image
690
710
"\n <p><a href=\" http://example.com\" ><img src=\" path/to/image.jpg\" ></a></p>\n "
691
711
692
712
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>"
693
718
end
694
719
695
720
def test_convert_TIDYLINK_rdoc_label
@@ -704,6 +729,23 @@ def test_convert_TIDYLINK_irc
704
729
assert_equal "\n <p><a href=\" irc://irc.freenode.net/#ruby-lang\" >ruby-lang</a></p>\n " , result
705
730
end
706
731
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
+
707
749
def test_convert_with_exclude_tag
708
750
assert_equal "\n <p><code>aaa</code>[:symbol]</p>\n " , @to . convert ( '+aaa+[:symbol]' )
709
751
assert_equal "\n <p><code>aaa[:symbol]</code></p>\n " , @to . convert ( '+aaa[:symbol]+' )
@@ -794,6 +836,11 @@ def test_handle_regexp_HYPERLINK_irc
794
836
assert_equal '<a href="irc://irc.freenode.net/#ruby-lang">irc.freenode.net/#ruby-lang</a>' , link
795
837
end
796
838
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
+
797
844
def test_list_verbatim_2
798
845
str = "* one\n verb1\n verb2\n * two\n "
799
846
@@ -903,5 +950,11 @@ def test_accept_table
903
950
assert_include ( res [ %r<<td[^<>]*>.*em.*</td>> ] , '<em>em</em>' )
904
951
assert_include ( res [ %r<<td[^<>]*>.*strong.*</td>> ] , '<strong>strong</strong>' )
905
952
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
906
959
end
907
960
0 commit comments