From c029eb6cf93cf77365e672d1dce13474dfa31274 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 4c6ce3ef179..baf0540d602 100644 --- a/lib/nokogiri/xml/document_fragment.rb +++ b/lib/nokogiri/xml/document_fragment.rb @@ -13,7 +13,7 @@ class DocumentFragment < Nokogiri::XML::Node class << self # Create a Nokogiri::XML::DocumentFragment from +tags+ - def parse(tags, options = ParseOptions::DEFAULT_XML, &block) + def 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 02eb8fc5811..76351673c67 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|