Skip to content
Browse files

Prevents HTML5 elements from being auto-closed when there are self-cl…

…osing tags within them.
  • Loading branch information...
1 parent 7dac6eb commit 680a7d51b3c233084f3ff0e5957870ad92ff2ef3 matthooks committed Nov 6, 2011
Showing with 12 additions and 3 deletions.
  1. +2 −1 lib/rack/pjax.rb
  2. +10 −2 spec/rack/pjax_spec.rb
View
3 lib/rack/pjax.rb
@@ -18,10 +18,11 @@ def call(env)
parsed_body = Hpricot(b)
container = parsed_body.at("[@data-pjax-container]")
if container
+ children = container.children
title = parsed_body.at("title")
new_body << title.to_s if title
- new_body << container.inner_html
+ new_body << children.map { |c| c.to_original_html }.join
else
new_body << b
end
View
12 spec/rack/pjax_spec.rb
@@ -10,8 +10,8 @@ def generate_app(options={})
Rack::Pjax.new(
lambda do |env|
[
- 200,
- {'Content-Type' => 'text/plain', 'Content-Length' => Rack::Utils.bytesize(body).to_s},
+ 200,
+ {'Content-Type' => 'text/plain', 'Content-Length' => Rack::Utils.bytesize(body).to_s},
[body]
]
end
@@ -36,6 +36,14 @@ def generate_app(options={})
body.should == "World!"
end
+ it "should handle self closing tags with HTML5 elements" do
+ self.class.app = generate_app(:body => '<html><body><div data-pjax-container><article>World!<img src="test.jpg" /></article></div></body></html>')
+
+ get "/", {}, {"HTTP_X_PJAX" => "true"}
+
+ body.should == '<article>World!<img src="test.jpg" /></article>'
+ end
+
it "should return the correct Content Length" do
get "/", {}, {"HTTP_X_PJAX" => "true"}
headers['Content-Length'].should == Rack::Utils.bytesize(body).to_s

0 comments on commit 680a7d5

Please sign in to comment.
Something went wrong with that request. Please try again.