Skip to content

Commit

Permalink
fix: XML::Reader#attribute_hash returns nil on error
Browse files Browse the repository at this point in the history
This restores the behavior from v1.13.7
  • Loading branch information
flavorjones committed Dec 6, 2022
1 parent a16b4bf commit 3375c1f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/nokogiri/xml_reader.c
Expand Up @@ -212,6 +212,10 @@ rb_xml_reader_attribute_hash(VALUE rb_reader)
}

c_node = xmlTextReaderExpand(c_reader);
if (c_node == NULL) {
return Qnil;
}

c_property = c_node->properties;
while (c_property != NULL) {
VALUE rb_name = NOKOGIRI_STR_NEW2(c_property->name);
Expand Down
24 changes: 24 additions & 0 deletions test/xml/test_reader.rb
Expand Up @@ -681,6 +681,30 @@ def test_nonexistent_attribute
reader.read # el
assert_nil(reader.attribute("other"))
end

def test_broken_markup_attribute_hash
xml = <<~XML
<root><foo bar="asdf">
XML
reader = Nokogiri::XML::Reader(xml)
reader.read # root
reader.read # foo

assert_equal("foo", reader.name)
assert_nil(reader.attribute_hash)
end

def test_broken_markup_namespaces
xml = <<~XML
<root><foo bar="asdf">
XML
reader = Nokogiri::XML::Reader(xml)
reader.read # root
reader.read # foo

assert_equal("foo", reader.name)
assert_nil(reader.namespaces)
end
end
end
end

0 comments on commit 3375c1f

Please sign in to comment.