Permalink
Browse files

[BUGFIX] Should inherit attribute namespace prefixes

  • Loading branch information...
1 parent bfa01c4 commit cd3b58d20459957798bd3b02c894531797a5cbb8 @benlangfeld committed Nov 25, 2011
Showing with 10 additions and 1 deletion.
  1. +4 −1 lib/niceogiri/xml/node.rb
  2. +6 −0 spec/niceogiri/xml/node_spec.rb
@@ -147,7 +147,10 @@ def inherit(node)
# @param [Hash] attrs a hash of attributes to set on the node
# @return [self]
def inherit_attrs(attrs)
- attrs.each { |name, value| self[name] = value }
+ attrs.each do |name, value|
+ attr_name = value.namespace ? [value.namespace.prefix, name].join(':') : name
+ self.write_attr attr_name, value
+ end
self
end
@@ -145,6 +145,12 @@ module XML
n2.to_s.should == n.to_s
end
+ it 'holds on to namespaces when inheriting attributes' do
+ n = Nokogiri::XML.parse('<foo xml:bar="http://bar.com"/>').root
+ n2 = Node.new('foo').inherit n
+ n2.to_s.should == n.to_s
+ end
+
it 'provides a mechanism to inherit attrs' do
n = Node.new 'foo'
n2 = Node.new 'foo'

0 comments on commit cd3b58d

Please sign in to comment.