Skip to content

Commit

Permalink
Prevents HTML5 elements from being auto-closed when there are self-cl…
Browse files Browse the repository at this point in the history
…osing tags within them.
  • Loading branch information
matthooks committed Nov 7, 2011
1 parent 7dac6eb commit 680a7d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/rack/pjax.rb
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions spec/rack/pjax_spec.rb
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 680a7d5

Please sign in to comment.