From c58aff651f4b57ec2372c9efb82e576923297fb2 Mon Sep 17 00:00:00 2001 From: "Davis W. Frank" Date: Thu, 14 Nov 2024 16:58:30 -0600 Subject: [PATCH] Updates HTML5::DocumentFragment.new, #parse with keyword arguments; --- lib/nokogiri/html5/document_fragment.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/nokogiri/html5/document_fragment.rb b/lib/nokogiri/html5/document_fragment.rb index 935ac6491dc..4232a275468 100644 --- a/lib/nokogiri/html5/document_fragment.rb +++ b/lib/nokogiri/html5/document_fragment.rb @@ -50,7 +50,7 @@ class << self # [Returns] # - [Nokogiri::XML::NodeSet] A node set containing the root nodes of the parsed fragment. # - def parse(tags, encoding = nil, positional_options_hash = nil, **options) + def parse(tags, encoding_ = nil, positional_options_hash = nil, encoding: encoding_, **options) unless positional_options_hash.nil? warn("Nokogiri::HTML5::DocumentFragment.parse: Passing options as an explicit hash is deprecated. Use keyword arguments instead. This will become an error in a future release.", uplevel: 1, category: :deprecated) options.merge!(positional_options_hash) @@ -62,7 +62,7 @@ def parse(tags, encoding = nil, positional_options_hash = nil, **options) document.encoding = "UTF-8" tags = HTML5.read_and_encode(tags, encoding) - new(document, tags, context, options) + new(document, tags, context, **options) end end @@ -77,11 +77,17 @@ def parse(tags, encoding = nil, positional_options_hash = nil, **options) attr_reader :quirks_mode # Create a document fragment. - def initialize(doc, tags = nil, context = nil, options = {}) # rubocop:disable Lint/MissingSuper + def initialize(doc, tags_ = nil, context_ = nil, positional_options_hash = nil, tags: tags_, context: context_, **options) # rubocop:disable Lint/MissingSuper + unless positional_options_hash.nil? + warn("Nokogiri::HTML5::DocumentFragment.new: Passing options as an explicit hash is deprecated. Use keyword arguments instead. This will become an error in a future release.", uplevel: 1, category: :deprecated) + options.merge!(positional_options_hash) + end + @document = doc @errors = [] return self unless tags + # TODO: Accept encoding as an argument to this method tags = Nokogiri::HTML5.read_and_encode(tags, nil) context = options.delete(:context) if options.key?(:context)