From 9959f5cda4f8e2c46e6695bea6134370f4036d3c Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 15 Sep 2014 22:04:03 +0200 Subject: [PATCH] Don't remove namespace attributes when registering When registering namespaces from an attributes list the attributes should _not_ be removed. This fixes #45. --- lib/oga/xml/element.rb | 11 ++++------- spec/oga/xml/element_spec.rb | 8 ++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb index 6126867..9b04f01 100644 --- a/lib/oga/xml/element.rb +++ b/lib/oga/xml/element.rb @@ -285,15 +285,12 @@ module Oga # has been registered the corresponding attribute is removed. # 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" # is not a registered namespace. - remove = attr.name == XMLNS_PREFIX || - attr.namespace_name == XMLNS_PREFIX - - register_namespace(attr.name, attr.value) if remove - - remove + if attr.name == XMLNS_PREFIX or attr.namespace_name == XMLNS_PREFIX + register_namespace(attr.name, attr.value) + end end end diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 6723654..c66fa8c 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -29,8 +29,8 @@ describe Oga::XML::Element do @element.namespaces['foo'].is_a?(Oga::XML::Namespace).should == true end - example 'remove the namespace attribute from the list of attributes' do - @element.attributes.empty?.should == true + example 'keep the attributes after registering the namespaces' do + @element.attributes.empty?.should == false end end @@ -44,10 +44,6 @@ describe Oga::XML::Element do example 'register the default namespace' do @element.namespaces['xmlns'].is_a?(Oga::XML::Namespace).should == true end - - example 'remove the namespace attribute from the list of attributes' do - @element.attributes.empty?.should == true - end end context '#attribute' do