diff --git a/lib/capybara/helpers.rb b/lib/capybara/helpers.rb
index c063c7bc..586d8e1a 100644
--- a/lib/capybara/helpers.rb
+++ b/lib/capybara/helpers.rb
@@ -42,10 +42,12 @@ module Capybara
def inject_asset_host(html)
if Capybara.asset_host && Nokogiri::HTML(html).css("base").empty?
match = html.match(/
/)
- html.clone.insert match.end(0), ""
- else
- html
+ if match
+ return html.clone.insert match.end(0), ""
+ end
end
+
+ html
end
##
diff --git a/lib/capybara/spec/session/save_page_spec.rb b/lib/capybara/spec/session/save_page_spec.rb
index 0dbf96d8..27e8b0b5 100644
--- a/lib/capybara/spec/session/save_page_spec.rb
+++ b/lib/capybara/spec/session/save_page_spec.rb
@@ -79,5 +79,13 @@ Capybara::SpecHelper.spec '#save_page' do
expect(result).to include('" do
+ @session.visit("/with_simple_html")
+ path = @session.save_page
+
+ result = File.read(path)
+ expect(result).to include("Bar")
+ end
end
end