Skip to content

Commit 8363add

Browse files
infewsflavorjones
authored andcommitted
Updates Node#parse with keyword arguments; updates tests to test parsing HTML4 and XML parsing w/ positional and keyword args
1 parent aaf76b0 commit 8363add

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

lib/nokogiri/xml/node.rb

Lines changed: 1 addition & 1 deletion
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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,36 @@ 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+
176+
def test_node_context_parsing_of_malformed_xml_fragment_without_recover_is_not_corrected_keyword
177+
skip("libxml2 2.14.0 no longer raises this error") if Nokogiri.uses_libxml?(">= 2.14.0")
178+
179+
doc = XML.parse("<root><body><div></div></body></roo")
180+
context_node = doc.at_css("div")
181+
assert_raises(Nokogiri::XML::SyntaxError) do
182+
context_node.parse("<div </div>", options: ParseOptions.new)
183+
end
184+
end
185+
156186
def test_node_context_parsing_of_malformed_xml_fragment_uses_the_right_class_to_recover
157187
doc = XML.parse("<root><body><div></div></body></root>")
158188
context_node = doc.at_css("div")

0 commit comments

Comments
 (0)