Skip to content
This repository has been archived by the owner on Jul 6, 2021. It is now read-only.

Inject js code only into valid html head tags #61

Closed
wants to merge 1 commit into from

Conversation

nathanhoel
Copy link

This addresses issue #60

I think the idea was that https://github.com/johnbintz/rack-livereload/blob/master/lib/rack/livereload/body_processor.rb#L73 would prevent this issue from occurring.
However RACK can pass the entire document as a single line. So when entering this section of code the @livereload_added would still be false and then it would proceed to replace all occurrences of the text <head> with the injected code.

This version pull request uses proper XML parsing to find the <head> element.

@@ -21,6 +21,7 @@ Gem::Specification.new do |s|

# specify any dependencies here; for example:
s.add_development_dependency "rspec"
s.add_development_dependency "rspec-its"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its has been made into it's own project separate from rspec so I fixed this.

@nathanhoel
Copy link
Author

After testing with some really complicated documents this doesn't work in all cases.
Nokogiri's XML and HTML parsing are not perfect and can lead to pretty corrupt HTML being returned :(

@nathanhoel nathanhoel closed this Dec 8, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant