Skip to content

Commit 5dedb57

Browse files
committed
1 parent ac35485 commit 5dedb57

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

lib/rdoc/generator/template/darkfish/index.rhtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
main_page = @files.find { |f| f.full_name == @options.main_page } then %>
1818
<%= main_page.description %>
1919
<%- else -%>
20-
<p>This is the API documentation for <%= @title %>.
20+
<p>This is the API documentation for <%= h @title %>.
2121
<%- end -%>
2222
</main>

test/rdoc/test_rdoc_generator_darkfish.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,22 @@ def test_template_stylesheets
248248
assert_include File.read('index.html'), %Q[href="./#{base}"]
249249
end
250250

251+
def test_title
252+
title = "RDoc Test".freeze
253+
@options.title = title
254+
@g.generate
255+
256+
assert_main_title(File.read('index.html'), title)
257+
end
258+
259+
def test_title_escape
260+
title = %[<script>alert("RDoc")</script>].freeze
261+
@options.title = title
262+
@g.generate
263+
264+
assert_main_title(File.read('index.html'), title)
265+
end
266+
251267
##
252268
# Asserts that +filename+ has a link count greater than 1 if hard links to
253269
# @tmpdir are supported.
@@ -271,4 +287,9 @@ def assert_hard_link filename
271287
"#{filename} is not hard-linked"
272288
end
273289

290+
def assert_main_title(content, title)
291+
title = CGI.escapeHTML(title)
292+
assert_equal(title, content[%r[<title>(.*?)<\/title>]im, 1])
293+
assert_include(content[%r[<main\s[^<>]*+>\s*(.*?)</main>]im, 1], title)
294+
end
274295
end

0 commit comments

Comments
 (0)