Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix XML::Reader working with non-existent attributes #1254

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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*)StringValuePtr(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*)StringValuePtr(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
15 changes: 15 additions & 0 deletions test/xml/test_reader.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "helper"

module Nokogiri
module XML
class TestReader < Nokogiri::TestCase
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