Skip to content

Commit

Permalink
fix XML::Reader working with non-existent attributes
Browse files Browse the repository at this point in the history
nokogiri now bundles a newer libxml, so doesn't have to
worry about old bad behavior, and the workaround was broken
  • Loading branch information
ccutrer authored and flavorjones committed May 28, 2016
1 parent d352d92 commit c7ff768
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
13 changes: 0 additions & 13 deletions ext/nokogiri/xml_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,6 @@ static VALUE reader_attribute(VALUE self, VALUE name)
name = StringValue(name) ;

value = xmlTextReaderGetAttribute(reader, (xmlChar*)StringValueCStr(name));
if(value == NULL) {
/* this section is an attempt to workaround older versions of libxml that
don't handle namespaces properly in all attribute-and-friends functions */
xmlChar *prefix = NULL ;
xmlChar *localname = xmlSplitQName2((xmlChar*)StringValueCStr(name), &prefix);
if (localname != NULL) {
value = xmlTextReaderLookupNamespace(reader, localname);
xmlFree(localname) ;
} else {
value = xmlTextReaderLookupNamespace(reader, prefix);
}
xmlFree(prefix);
}
if(value == NULL) return Qnil;

rb_value = NOKOGIRI_STR_NEW2(value);
Expand Down
8 changes: 8 additions & 0 deletions test/xml/test_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,14 @@ def test_correct_inner_xml_inclusion
assert(has_child2[1])
assert(!has_child2[0])
end

def test_nonexistent_attribute
require 'nokogiri'
reader = Nokogiri::XML::Reader("<root xmlns='bob'><el attr='fred' /></root>")
reader.read
reader.read
assert_equal reader.attribute('other'), nil
end
end
end
end

0 comments on commit c7ff768

Please sign in to comment.