Permalink
Browse files

[BUGFIX] Better namespace inheritance

  • Loading branch information...
1 parent ffe151e commit d5393639d5c051499a8a1af71e8a7b0aecc5bc24 @benlangfeld committed Jun 25, 2012
Showing with 8 additions and 2 deletions.
  1. +1 −1 lib/niceogiri/xml/node.rb
  2. +7 −1 spec/niceogiri/xml/node_spec.rb
@@ -133,7 +133,7 @@ def set_content_for(node, content = nil)
# @param [XML::Node] node the node to inherit
# @return [self]
def inherit(node)
- nokogiri_namespace = node.namespace
+ self.namespace = node.namespace.href if node.namespace
inherit_attrs node.attributes
node.children.each { |c| self << c.dup }
self
@@ -139,12 +139,18 @@ module XML
n2.to_s.should == n.to_s
end
- it 'holds on to namespaces when inheriting content' do
+ it 'holds on to namespace prefixes when inheriting content' do
n = Nokogiri::XML.parse('<message><bar:foo xmlns:bar="http://bar.com"></message>').root
n2 = Node.new('message').inherit n
n2.to_s.should == n.to_s
end
+ it 'holds on to namespaces when inheriting content' do
+ n = Nokogiri::XML.parse('<message xmlns="foobar"/>').root
+ n2 = Node.new('message').inherit n
+ n2.to_s.should == n.to_s
+ end
+
it 'holds on to namespaces without a prefix when inheriting content' do
n = Nokogiri::XML.parse('<message><bar:foo xmlns="http://bar.com"></message>').root
n2 = Node.new('message').inherit n

0 comments on commit d539363

Please sign in to comment.