Only inject JS into the first instance of <head>.

This commit is contained in:
Trevor Smith 2015-02-27 19:23:37 -07:00
parent 952ea670dd
commit c52c5e1b42
2 changed files with 9 additions and 1 deletions

View File

@ -71,7 +71,7 @@ module Rack
@new_body.each do |line| @new_body.each do |line|
if !@livereload_added && line['<head'] if !@livereload_added && line['<head']
line.gsub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} } line.sub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} }
@livereload_added = true @livereload_added = true
end end

View File

@ -143,6 +143,14 @@ describe Rack::LiveReload::BodyProcessor do
end end
end end
context 'in inline javascript containing markup' do
let(:page_html) { '<head></head><script>var html="<head></head>";</script>' }
it 'should not add the livereload js' do
processed_body.should include('var html="<head></head>"')
end
end
context 'not vendored' do context 'not vendored' do
before do before do
processor.stubs(:use_vendored?).returns(false) processor.stubs(:use_vendored?).returns(false)