Skip to content

Commit

Permalink
Updates Node#parse with keyword arguments; updates tests to test pars…
Browse files Browse the repository at this point in the history
…ing HTML4 and XML parsing w/ positional and keyword args
  • Loading branch information
infews committed Nov 14, 2024
1 parent aaf76b0 commit 3ecce35
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/nokogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ def fragment(tags)
# Parse +string_or_io+ as a document fragment within the context of
# *this* node. Returns a XML::NodeSet containing the nodes parsed from
# +string_or_io+.
def parse(string_or_io, options = nil)
def parse(string_or_io, options_ = nil, options: options_)
##
# When the current node is unparented and not an element node, use the
# document as the parsing context instead. Otherwise, the in-context
Expand Down
29 changes: 29 additions & 0 deletions test/xml/test_node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,35 @@ def test_node_context_parsing_of_malformed_html_fragment_without_recover_is_not_
end
end

def test_node_context_parsing_of_malformed_html_fragment_without_recover_is_not_corrected_keyword
skip("libxml2 2.14.0 no longer raises this error") if Nokogiri.uses_libxml?(">= 2.14.0")

doc = HTML4.parse("<html><body><div></div></body></html>")
context_node = doc.at_css("div")
assert_raises(Nokogiri::XML::SyntaxError) do
context_node.parse("<div </div>", options: ParseOptions.new)
end
end

def test_node_context_parsing_of_malformed_xml_fragment_without_recover_is_not_corrected
skip("libxml2 2.14.0 no longer raises this error") if Nokogiri.uses_libxml?(">= 2.14.0")

doc = XML.parse("<root><body><div></div></body></roo")
context_node = doc.at_css("div")
assert_raises(Nokogiri::XML::SyntaxError) do
context_node.parse("<div </div>", &:strict)
end
end
def test_node_context_parsing_of_malformed_xml_fragment_without_recover_is_not_corrected_keyword
skip("libxml2 2.14.0 no longer raises this error") if Nokogiri.uses_libxml?(">= 2.14.0")

doc = XML.parse("<root><body><div></div></body></roo")
context_node = doc.at_css("div")
assert_raises(Nokogiri::XML::SyntaxError) do
context_node.parse("<div </div>", options: ParseOptions.new)
end
end

def test_node_context_parsing_of_malformed_xml_fragment_uses_the_right_class_to_recover
doc = XML.parse("<root><body><div></div></body></root>")
context_node = doc.at_css("div")
Expand Down

0 comments on commit 3ecce35

Please sign in to comment.