Nobuyoshi Nakada 2022-03-28 18:36:56 +09:00 коммит произвёл git
Родитель 0472effc41
Коммит deaa656608
2 изменённых файлов: 29 добавлений и 2 удалений

Просмотреть файл

@ -154,9 +154,13 @@ class RDoc::Markup::ToHtml < RDoc::Markup::Formatter
text =~ /^\{(.*)\}\[(.*?)\]$/ or text =~ /^(\S+)\[(.*?)\]$/
label = $1
url = $2
url = CGI.escapeHTML($2)
label = handle_RDOCLINK label if /^rdoc-image:/ =~ label
if /^rdoc-image:/ =~ label
label = handle_RDOCLINK(label)
else
label = CGI.escapeHTML(label)
end
gen_url url, label
end

Просмотреть файл

@ -704,6 +704,23 @@ EXPECTED
assert_equal "\n<p><a href=\"irc://irc.freenode.net/#ruby-lang\">ruby-lang</a></p>\n", result
end
def test_convert_TIDYLINK_escape_text
assert_escaped '<script>', '{<script>alert`link text`</script>}[a]'
assert_escaped '<script>', 'x:/<script>alert(1);</script>[[]'
end
def test_convert_TIDYLINK_escape_javascript
assert_not_include '{click}[javascript:alert`javascript_scheme`]', '<a href="javascript:'
end
def test_convert_TIDYLINK_escape_onmouseover
assert_escaped '"/onmouseover="', '{onmouseover}[http://"/onmouseover="alert`on_mouse_link`"]'
end
def test_convert_TIDYLINK_escape_onerror
assert_escaped '"onerror="', '{link_image}[http://"onerror="alert`link_image`".png]'
end
def test_convert_with_exclude_tag
assert_equal "\n<p><code>aaa</code>[:symbol]</p>\n", @to.convert('+aaa+[:symbol]')
assert_equal "\n<p><code>aaa[:symbol]</code></p>\n", @to.convert('+aaa[:symbol]+')
@ -903,5 +920,11 @@ EXPECTED
assert_include(res[%r<<td[^<>]*>.*em.*</td>>], '<em>em</em>')
assert_include(res[%r<<td[^<>]*>.*strong.*</td>>], '<strong>strong</strong>')
end
def assert_escaped(unexpected, code)
result = @to.convert(code)
assert_not_include result, unexpected
assert_include result, CGI.escapeHTML(unexpected)
end
end