Skip to content

Commit

Permalink
Merge pull request #646 from bootstraponline/master
Browse files Browse the repository at this point in the history
Fix #645
  • Loading branch information
bootstraponline committed Mar 5, 2013
2 parents a31ba16 + 8ebc2f7 commit 544d499
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/gollum/frontend/views/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,9 @@ def find_header_node(doc)
#
def page_header_from_content(content)
doc = build_document(content)
title = find_header_node(doc)
Sanitize.clean(title.to_xml( @@to_xml )).strip unless title.empty?
title = find_header_node(doc).inner_text.strip
title = nil if title.empty?
title
end

# Returns page content without title if it was extracted.
Expand Down
46 changes: 46 additions & 0 deletions test/test_page_view.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# ~*~ encoding: utf-8 ~*~
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
require File.expand_path '../../lib/gollum/frontend/views/page', __FILE__

context "Precious::Views::Page" do
setup do
@path = testpath("examples/test.git")
FileUtils.rm_rf(@path)
@repo = Grit::Repo.init_bare(@path)
@wiki = Gollum::Wiki.new(@path)
end

teardown do
FileUtils.rm_r(File.join(File.dirname(__FILE__), *%w[examples test.git]))
end

test "h1 title sanitizes correctly" do
title = 'H1'
@wiki.write_page(title, :markdown, '# 1 & 2 <script>alert("js")</script>' + "\n # 3", commit_details)
page = @wiki.page(title)

@view = Precious::Views::Page.new
@view.instance_variable_set :@page, page
@view.instance_variable_set :@content, page.formatted_data
@view.instance_variable_set :@h1_title, true

# Test page_header_from_content(@content)
actual = @view.title
assert_equal '1 & 2', actual
end

test "h1 title can be disabled" do
title = 'H1'
@wiki.write_page(title, :markdown, '# 1 & 2 <script>alert("js")</script>' + "\n # 3", commit_details)
page = @wiki.page(title)

@view = Precious::Views::Page.new
@view.instance_variable_set :@page, page
@view.instance_variable_set :@content, page.formatted_data
@view.instance_variable_set :@h1_title, false

# Title is based on file name when h1_title is false.
actual = @view.title
assert_equal 'H1', title
end
end

0 comments on commit 544d499

Please sign in to comment.