From 804646cc5e339eb2163ab5e7f568199b1c68a464 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 17 Nov 2014 00:01:16 +0100 Subject: [PATCH] Don't modify raw namespaces. When calling Element#available_namespaces the list of namespaces returned by Element#namespaces must not be modified. --- lib/oga/xml/element.rb | 2 +- spec/oga/xml/element_spec.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb index bfc7907..2d990c6 100644 --- a/lib/oga/xml/element.rb +++ b/lib/oga/xml/element.rb @@ -273,7 +273,7 @@ module Oga # @return [Hash] # def available_namespaces - merged = namespaces + merged = namespaces.dup node = parent while node && node.respond_to?(:namespaces) diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 3d6ee54..44c51c3 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -418,6 +418,10 @@ describe Oga::XML::Element do example 'return the "baz" namespace for the parent' do @parent_ns['baz'].uri.should == 'yyy' end + + example 'do not modify the list of direct namespaces' do + @child.namespaces.key?('foo').should == false + end end context '#self_closing?' do