diff --git a/lib/nokogiri/xml.rb b/lib/nokogiri/xml.rb index 888c1f39009..08be5e4550c 100644 --- a/lib/nokogiri/xml.rb +++ b/lib/nokogiri/xml.rb @@ -29,10 +29,9 @@ def parse(thing, url = nil, encoding = nil, options = ParseOptions::DEFAULT_XML, Document.parse(thing, url, encoding, options, &block) end - #### - # Parse a fragment from +string+ in to a NodeSet. - def fragment(string, options = ParseOptions::DEFAULT_XML, &block) - XML::DocumentFragment.parse(string, options, &block) + # Convenience method for Nokogiri::XML::DocumentFragment.parse + def fragment(...) + XML::DocumentFragment.parse(...) end end end diff --git a/test/xml/test_document_fragment.rb b/test/xml/test_document_fragment.rb index 76351673c67..8be61d062f6 100644 --- a/test/xml/test_document_fragment.rb +++ b/test/xml/test_document_fragment.rb @@ -386,6 +386,16 @@ def test_for_libxml_in_context_memory_badness_when_encountering_encoding_errors end end + it "accepts kwargs" do + frag = Nokogiri::XML.fragment(input, options: xml_default) + assert_equal("foo", frag.to_html) + refute_empty(frag.errors) + + assert_raises(Nokogiri::SyntaxError) do + Nokogiri::XML.fragment(input, options: xml_strict) + end + end + it "takes a config block" do default_config = nil Nokogiri::XML.fragment(input) do |config|