Skip to content
Browse files

[BUGFIX] Inheriting nodes should copy namespaces on child nodes expli…

…citly

Fixes JRuby
  • Loading branch information...
1 parent d539363 commit 54d5027b6b974f56129fab747fa3e74e78661f20 @benlangfeld committed Jun 25, 2012
Showing with 11 additions and 2 deletions.
  1. +7 −1 lib/niceogiri/xml/node.rb
  2. +4 −1 spec/niceogiri/xml/node_spec.rb
View
8 lib/niceogiri/xml/node.rb
@@ -135,7 +135,13 @@ def set_content_for(node, content = nil)
def inherit(node)
self.namespace = node.namespace.href if node.namespace
inherit_attrs node.attributes
- node.children.each { |c| self << c.dup }
+ node.children.each do |c|
+ self << (n = c.dup)
+ if c.namespace
+ ns = n.add_namespace c.namespace.prefix, c.namespace.href
+ n.namespace = ns
+ end
+ end
self
end
View
5 spec/niceogiri/xml/node_spec.rb
@@ -146,9 +146,12 @@ module XML
end
it 'holds on to namespaces when inheriting content' do
- n = Nokogiri::XML.parse('<message xmlns="foobar"/>').root
+ n = Nokogiri::XML.parse('<message xmlns="foobar"><body xmlns="barfoo"/></message>').root
n2 = Node.new('message').inherit n
n2.to_s.should == n.to_s
+ n2.namespace.href.should be == 'foobar'
+ body = n2.children.first
+ body.namespace.href.should be == 'barfoo'
end
it 'holds on to namespaces without a prefix when inheriting content' do

0 comments on commit 54d5027

Please sign in to comment.
Something went wrong with that request. Please try again.