Don't remove namespace attributes when registering

When registering namespaces from an attributes list the attributes should _not_
be removed.

This fixes #45.
This commit is contained in:
Yorick Peterse 2014-09-15 22:04:03 +02:00
parent 795e669632
commit 9959f5cda4
2 changed files with 6 additions and 13 deletions

View File

@ -285,15 +285,12 @@ module Oga
# has been registered the corresponding attribute is removed. # has been registered the corresponding attribute is removed.
# #
def register_namespaces_from_attributes def register_namespaces_from_attributes
self.attributes = attributes.reject do |attr| attributes.each do |attr|
# We're using `namespace_name` opposed to `namespace.name` as "xmlns" # We're using `namespace_name` opposed to `namespace.name` as "xmlns"
# is not a registered namespace. # is not a registered namespace.
remove = attr.name == XMLNS_PREFIX || if attr.name == XMLNS_PREFIX or attr.namespace_name == XMLNS_PREFIX
attr.namespace_name == XMLNS_PREFIX register_namespace(attr.name, attr.value)
end
register_namespace(attr.name, attr.value) if remove
remove
end end
end end

View File

@ -29,8 +29,8 @@ describe Oga::XML::Element do
@element.namespaces['foo'].is_a?(Oga::XML::Namespace).should == true @element.namespaces['foo'].is_a?(Oga::XML::Namespace).should == true
end end
example 'remove the namespace attribute from the list of attributes' do example 'keep the attributes after registering the namespaces' do
@element.attributes.empty?.should == true @element.attributes.empty?.should == false
end end
end end
@ -44,10 +44,6 @@ describe Oga::XML::Element do
example 'register the default namespace' do example 'register the default namespace' do
@element.namespaces['xmlns'].is_a?(Oga::XML::Namespace).should == true @element.namespaces['xmlns'].is_a?(Oga::XML::Namespace).should == true
end end
example 'remove the namespace attribute from the list of attributes' do
@element.attributes.empty?.should == true
end
end end
context '#attribute' do context '#attribute' do