Skip to content

Commit

Permalink
[BUGFIX] Inheriting nodes should copy namespaces on child nodes expli…
Browse files Browse the repository at this point in the history
…citly

Fixes JRuby
  • Loading branch information
benlangfeld committed Jun 25, 2012
1 parent d539363 commit 54d5027
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/niceogiri/xml/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion spec/niceogiri/xml/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 54d5027

Please sign in to comment.