diff --git a/Guardfile b/Guardfile index f24ee41..5279189 100644 --- a/Guardfile +++ b/Guardfile @@ -1,7 +1,7 @@ # A sample Guardfile # More info at https://github.com/guard/guard#readme -guard 'rspec', :cli => '-c' do +guard 'rspec', :version => 2, :cli => '-c' do watch(%r{^spec/.+_spec\.rb$}) watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } watch('spec/spec_helper.rb') { "spec" } diff --git a/lib/rack/livereload.rb b/lib/rack/livereload.rb index 38b2ef0..bec1bf9 100644 --- a/lib/rack/livereload.rb +++ b/lib/rack/livereload.rb @@ -4,6 +4,7 @@ module Rack class LiveReload LIVERELOAD_JS_PATH = '/__rack/livereload.js' LIVERELOAD_LOCAL_URI = 'http://localhost:35729/livereload.js' + HEAD_TAG_REGEX = /
|/ BAD_USER_AGENTS = [ %r{MSIE} ] @@ -77,7 +78,7 @@ module Rack template = ERB.new(::File.read(::File.expand_path('../../../skel/livereload.html.erb', __FILE__))) if line[']*>/) { |match| %{#{match}#{template.result(binding)}} } + line.gsub!(HEAD_TAG_REGEX) { |match| %{#{match}#{template.result(binding)}} } end headers["X-Rack-LiveReload"] = '1' diff --git a/spec/rack/livereload_spec.rb b/spec/rack/livereload_spec.rb index 4652732..649a9e6 100644 --- a/spec/rack/livereload_spec.rb +++ b/spec/rack/livereload_spec.rb @@ -223,5 +223,22 @@ describe Rack::LiveReload do it { should be_bad_browser(user_agent) } end + + describe 'head tag regex' do + let(:regex) { described_class::HEAD_TAG_REGEX } + subject { regex } + + it { should be_kind_of(Regexp) } + + it 'only picks a valid tag' do + regex.match("").to_s.should eq('') + regex.match("