diff --git a/lib/nokogiri/html.rb b/lib/nokogiri/html.rb index 617cf9c7fe..276c2deeb2 100644 --- a/lib/nokogiri/html.rb +++ b/lib/nokogiri/html.rb @@ -26,7 +26,7 @@ def parse thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT #### # Parse a fragment from +string+ in to a NodeSet. - def fragment string, encoding = nil, options = nil, &block + def fragment string, encoding = nil, options = XML::ParseOptions::DEFAULT_HTML, &block HTML::DocumentFragment.parse string, encoding, options, &block end end diff --git a/lib/nokogiri/html/document_fragment.rb b/lib/nokogiri/html/document_fragment.rb index 3546d99a4a..eab510820c 100644 --- a/lib/nokogiri/html/document_fragment.rb +++ b/lib/nokogiri/html/document_fragment.rb @@ -3,7 +3,7 @@ module HTML class DocumentFragment < Nokogiri::XML::DocumentFragment #### # Create a Nokogiri::XML::DocumentFragment from +tags+, using +encoding+ - def self.parse tags, encoding = nil, options = nil + def self.parse tags, encoding = nil, options = XML::ParseOptions::DEFAULT_HTML, &block doc = HTML::Document.new encoding ||= if tags.respond_to?(:encoding) @@ -19,10 +19,10 @@ def self.parse tags, encoding = nil, options = nil doc.encoding = encoding - new(doc, tags, nil, options) + new(doc, tags, nil, options, &block) end - def initialize document, tags = nil, ctx = nil, options = nil, &block + def initialize document, tags = nil, ctx = nil, options = XML::ParseOptions::DEFAULT_HTML, &block return self unless tags if ctx diff --git a/test/html/test_document_fragment.rb b/test/html/test_document_fragment.rb index 3a85740b42..6cd3da60d7 100644 --- a/test/html/test_document_fragment.rb +++ b/test/html/test_document_fragment.rb @@ -38,6 +38,14 @@ def test_colons_are_not_removed assert_match(/3:30/, doc.to_s) end + def test_passed_options_have_an_effect + html = "testtest", doc.to_html + end + def test_parse_encoding fragment = "
hello world
" f = Nokogiri::HTML::DocumentFragment.parse fragment, 'ISO-8859-1'