Skip to content

Commit 3ecce35

Browse files
committed
Updates Node#parse with keyword arguments; updates tests to test parsing HTML4 and XML parsing w/ positional and keyword args
1 parent aaf76b0 commit 3ecce35

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/nokogiri/xml/node.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ def fragment(tags)
11021102
# Parse +string_or_io+ as a document fragment within the context of
11031103
# *this* node. Returns a XML::NodeSet containing the nodes parsed from
11041104
# +string_or_io+.
1105-
def parse(string_or_io, options = nil)
1105+
def parse(string_or_io, options_ = nil, options: options_)
11061106
##
11071107
# When the current node is unparented and not an element node, use the
11081108
# document as the parsing context instead. Otherwise, the in-context

test/xml/test_node.rb

+29
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,35 @@ def test_node_context_parsing_of_malformed_html_fragment_without_recover_is_not_
153153
end
154154
end
155155

156+
def test_node_context_parsing_of_malformed_html_fragment_without_recover_is_not_corrected_keyword
157+
skip("libxml2 2.14.0 no longer raises this error") if Nokogiri.uses_libxml?(">= 2.14.0")
158+
159+
doc = HTML4.parse("<html><body><div></div></body></html>")
160+
context_node = doc.at_css("div")
161+
assert_raises(Nokogiri::XML::SyntaxError) do
162+
context_node.parse("<div </div>", options: ParseOptions.new)
163+
end
164+
end
165+
166+
def test_node_context_parsing_of_malformed_xml_fragment_without_recover_is_not_corrected
167+
skip("libxml2 2.14.0 no longer raises this error") if Nokogiri.uses_libxml?(">= 2.14.0")
168+
169+
doc = XML.parse("<root><body><div></div></body></roo")
170+
context_node = doc.at_css("div")
171+
assert_raises(Nokogiri::XML::SyntaxError) do
172+
context_node.parse("<div </div>", &:strict)
173+
end
174+
end
175+
def test_node_context_parsing_of_malformed_xml_fragment_without_recover_is_not_corrected_keyword
176+
skip("libxml2 2.14.0 no longer raises this error") if Nokogiri.uses_libxml?(">= 2.14.0")
177+
178+
doc = XML.parse("<root><body><div></div></body></roo")
179+
context_node = doc.at_css("div")
180+
assert_raises(Nokogiri::XML::SyntaxError) do
181+
context_node.parse("<div </div>", options: ParseOptions.new)
182+
end
183+
end
184+
156185
def test_node_context_parsing_of_malformed_xml_fragment_uses_the_right_class_to_recover
157186
doc = XML.parse("<root><body><div></div></body></root>")
158187
context_node = doc.at_css("div")

0 commit comments

Comments
 (0)