mirror of
https://github.com/teamcapybara/capybara.git
synced 2022-11-09 12:08:07 -05:00
inject_asset_host should not raise if <head> is missing
Previously, if you had Capybara.asset_host defined and tried to `save_page` on a document without a <head> tag (like plain text) `inject_asset_host` would crash trying to string-replace a <base> tag onto the nonexistant <head>. Since there's probably no need for it to successfully inject a <base> into such documents, now it will return the original content when there is no <head> present.
This commit is contained in:
parent
90f5d374fd
commit
e4db955395
2 changed files with 13 additions and 3 deletions
|
@ -42,12 +42,14 @@ module Capybara
|
|||
def inject_asset_host(html)
|
||||
if Capybara.asset_host && Nokogiri::HTML(html).css("base").empty?
|
||||
match = html.match(/<head[^<]*?>/)
|
||||
html.clone.insert match.end(0), "<base href='#{Capybara.asset_host}' />"
|
||||
else
|
||||
html
|
||||
if match
|
||||
return html.clone.insert match.end(0), "<base href='#{Capybara.asset_host}' />"
|
||||
end
|
||||
end
|
||||
|
||||
html
|
||||
end
|
||||
|
||||
##
|
||||
#
|
||||
# Checks if the given count matches the given count options.
|
||||
|
|
|
@ -79,5 +79,13 @@ Capybara::SpecHelper.spec '#save_page' do
|
|||
expect(result).to include('<html')
|
||||
expect(result).not_to include("http://example.com")
|
||||
end
|
||||
|
||||
it "executes successfully even if the page is missing a <head>" do
|
||||
@session.visit("/with_simple_html")
|
||||
path = @session.save_page
|
||||
|
||||
result = File.read(path)
|
||||
expect(result).to include("Bar")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue