From ce05c0db0a4569eaa7f8f0121d2137827cebb625 Mon Sep 17 00:00:00 2001 From: Brian Lesperance Date: Thu, 14 Nov 2024 15:30:18 -0600 Subject: [PATCH] Nokogiri::XML.fragment() supports argument forwarding Related to https://github.com/sparklemotion/nokogiri#3323 --- lib/nokogiri/xml.rb | 7 +++---- test/xml/test_document_fragment.rb | 10 ++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) 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|