Skip to content

Commit

Permalink
Merge PR #503 into fix_title
Browse files Browse the repository at this point in the history
  • Loading branch information
knu committed Jun 2, 2018
2 parents 3b1e194 + 7a4ab37 commit 8229af0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mechanize/page.rb
Expand Up @@ -58,7 +58,7 @@ def initialize(uri=nil, response=nil, body=nil, code=nil, mech=nil)
def title
@title ||=
if doc = parser
title = doc.search('title').inner_text
title = doc.search('html > head > title').inner_text
title.empty? ? nil : title
end
end
Expand Down
26 changes: 26 additions & 0 deletions test/test_mechanize_page.rb
Expand Up @@ -250,5 +250,31 @@ def test_search_bad_selectors
assert_empty page.links_with(:search => '//img')
end

def test_multiple_titles
page = html_page <<-BODY
<!doctype html>
<html>
<head>
<title>HTMLTITLE</title>
</head>
<body>
<svg>
<title>SVGTITLE</title>
<metadata id="metadata5">
<rdf:RDF>
<cc:Work>
<dc:title>RDFDCTITLE</dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g></g>
</svg>
</body>
</html>
BODY

assert_equal page.title, "HTMLTITLE"
end

end

0 comments on commit 8229af0

Please sign in to comment.