File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
lib/rdoc/generator/template/darkfish Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff 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
274295end
You can’t perform that action at this time.
0 commit comments