Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates HTML5::DocumentFragment.new, #parse with keyword arguments; #3335

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/nokogiri/html5/document_fragment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand Down