don't insert into <header> tags.

This commit is contained in:
Matthew Lehner 2012-12-13 14:41:30 -08:00
parent ebeb331f0f
commit cc1ad71a62
2 changed files with 12 additions and 1 deletions

View File

@ -77,7 +77,7 @@ module Rack
template = ERB.new(::File.read(::File.expand_path('../../../skel/livereload.html.erb', __FILE__)))
if line['<head']
line.gsub!(/<head[^>]*>/) { |match| %{#{match}#{template.result(binding)}} }
line.gsub!(/<head([^(er)]|\s)[^>]*>/) { |match| %{#{match}#{template.result(binding)}} }
end
headers["X-Rack-LiveReload"] = '1'

View File

@ -107,6 +107,17 @@ describe Rack::LiveReload do
end
end
context 'in header tags' do
let(:page_html) { "<header class='hero'><h1>Just a normal header tag</h1></header>" }
let(:body_dom) { Nokogiri::XML(body) }
it 'should not add the livereload js' do
body_dom.at_css("header")[:class].should == 'hero'
body_dom.css('script').should be_empty
end
end
context 'not vendored' do
before do
middleware.stubs(:use_vendored?).returns(false)