From 9dd09462bd3dd9259421bf877d96b7e805961180 Mon Sep 17 00:00:00 2001 From: Brian Lesperance Date: Thu, 14 Nov 2024 12:37:01 -0600 Subject: [PATCH] XML::DocumentFragment.parse supports kwargs Related to sparklemotion/nokogiri#3323 --- lib/nokogiri/xml/document_fragment.rb | 2 +- test/xml/test_document_fragment.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/nokogiri/xml/document_fragment.rb b/lib/nokogiri/xml/document_fragment.rb index dbdc46b424..fb92337862 100644 --- a/lib/nokogiri/xml/document_fragment.rb +++ b/lib/nokogiri/xml/document_fragment.rb @@ -11,7 +11,7 @@ class DocumentFragment < Nokogiri::XML::Node #### # Create a Nokogiri::XML::DocumentFragment from +tags+ - def self.parse(tags, options = ParseOptions::DEFAULT_XML, &block) + def self.parse(tags, options_ = ParseOptions::DEFAULT_XML, options: options_, &block) new(XML::Document.new, tags, nil, options, &block) end diff --git a/test/xml/test_document_fragment.rb b/test/xml/test_document_fragment.rb index 02eb8fc581..76351673c6 100644 --- a/test/xml/test_document_fragment.rb +++ b/test/xml/test_document_fragment.rb @@ -416,6 +416,16 @@ def test_for_libxml_in_context_memory_badness_when_encountering_encoding_errors end end + it "accepts kwargs" do + frag = Nokogiri::XML::DocumentFragment.parse(input, options: xml_default) + assert_equal("foo", frag.to_html) + refute_empty(frag.errors) + + assert_raises(Nokogiri::SyntaxError) do + Nokogiri::XML::DocumentFragment.parse(input, options: xml_strict) + end + end + it "takes a config block" do default_config = nil Nokogiri::XML::DocumentFragment.parse(input) do |config|