Update Action View and Action Dispatch to use HTML5 when available
This commit is contained in:
parent
676fdb1414
commit
2362f57cd8
@ -1,3 +1,10 @@
|
|||||||
|
* `ActionDispatch::Assertions#html_document` uses Nokogiri's HTML5 parser if it is available.
|
||||||
|
|
||||||
|
The HTML5 parser better represents what the DOM would be in a browser. Previously this test
|
||||||
|
helper always used Nokogiri's HTML4 parser.
|
||||||
|
|
||||||
|
*Mike Dalessio*
|
||||||
|
|
||||||
* The `with_routing` helper can now be called at the class level. When called at the class level, the routes will
|
* The `with_routing` helper can now be called at the class level. When called at the class level, the routes will
|
||||||
be setup before each test, and reset after every test. For example:
|
be setup before each test, and reset after every test. For example:
|
||||||
|
|
||||||
|
@ -15,8 +15,10 @@ module Assertions
|
|||||||
def html_document
|
def html_document
|
||||||
@html_document ||= if @response.media_type&.end_with?("xml")
|
@html_document ||= if @response.media_type&.end_with?("xml")
|
||||||
Nokogiri::XML::Document.parse(@response.body)
|
Nokogiri::XML::Document.parse(@response.body)
|
||||||
|
elsif defined?(Nokogiri::HTML5)
|
||||||
|
Nokogiri::HTML5::Document.parse(@response.body)
|
||||||
else
|
else
|
||||||
Nokogiri::HTML::Document.parse(@response.body)
|
Nokogiri::HTML4::Document.parse(@response.body)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -177,9 +177,17 @@ def _test_case
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def html_document_class
|
||||||
|
defined?(Nokogiri::HTML5) ? Nokogiri::HTML5::Document : Nokogiri::HTML4::Document
|
||||||
|
end
|
||||||
|
|
||||||
|
def html_document_fragment_class
|
||||||
|
defined?(Nokogiri::HTML5) ? Nokogiri::HTML5::DocumentFragment : Nokogiri::HTML4::DocumentFragment
|
||||||
|
end
|
||||||
|
|
||||||
# Need to experiment if this priority is the best one: rendered => output_buffer
|
# Need to experiment if this priority is the best one: rendered => output_buffer
|
||||||
def document_root_element
|
def document_root_element
|
||||||
Nokogiri::HTML::Document.parse(@rendered.blank? ? @output_buffer.to_str : @rendered).root
|
html_document_class.parse(@rendered.blank? ? @output_buffer.to_str : @rendered).root
|
||||||
end
|
end
|
||||||
|
|
||||||
module Locals
|
module Locals
|
||||||
|
@ -986,7 +986,7 @@ def protect_against_forgery?
|
|||||||
|
|
||||||
private
|
private
|
||||||
def root_elem(rendered_content)
|
def root_elem(rendered_content)
|
||||||
Nokogiri::HTML::DocumentFragment.parse(rendered_content).children.first # extract from nodeset
|
html_document_fragment_class.parse(rendered_content).children.first # extract from nodeset
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_default_enforce_utf8(value)
|
def with_default_enforce_utf8(value)
|
||||||
|
Loading…
Reference in New Issue
Block a user