[ruby/rdoc] Escape main title
https://hackerone.com/reports/1187156 https://github.com/ruby/rdoc/commit/5dedb5741d
This commit is contained in:
parent
586e18b946
commit
8d0b2162a0
@ -17,6 +17,6 @@
|
|||||||
main_page = @files.find { |f| f.full_name == @options.main_page } then %>
|
main_page = @files.find { |f| f.full_name == @options.main_page } then %>
|
||||||
<%= main_page.description %>
|
<%= main_page.description %>
|
||||||
<%- else -%>
|
<%- else -%>
|
||||||
<p>This is the API documentation for <%= @title %>.
|
<p>This is the API documentation for <%= h @title %>.
|
||||||
<%- end -%>
|
<%- end -%>
|
||||||
</main>
|
</main>
|
||||||
|
@ -248,6 +248,22 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
|
|||||||
assert_include File.read('index.html'), %Q[href="./#{base}"]
|
assert_include File.read('index.html'), %Q[href="./#{base}"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_title
|
||||||
|
title = "RDoc Test".freeze
|
||||||
|
@options.title = title
|
||||||
|
@g.generate
|
||||||
|
|
||||||
|
assert_main_title(File.read('index.html'), title)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_title_escape
|
||||||
|
title = %[<script>alert("RDoc")</script>].freeze
|
||||||
|
@options.title = title
|
||||||
|
@g.generate
|
||||||
|
|
||||||
|
assert_main_title(File.read('index.html'), title)
|
||||||
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
# Asserts that +filename+ has a link count greater than 1 if hard links to
|
# Asserts that +filename+ has a link count greater than 1 if hard links to
|
||||||
# @tmpdir are supported.
|
# @tmpdir are supported.
|
||||||
@ -271,4 +287,9 @@ class TestRDocGeneratorDarkfish < RDoc::TestCase
|
|||||||
"#{filename} is not hard-linked"
|
"#{filename} is not hard-linked"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_main_title(content, title)
|
||||||
|
title = CGI.escapeHTML(title)
|
||||||
|
assert_equal(title, content[%r[<title>(.*?)<\/title>]im, 1])
|
||||||
|
assert_include(content[%r[<main\s[^<>]*+>\s*(.*?)</main>]im, 1], title)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user