diff --git a/lib/oga/xml/element.rb b/lib/oga/xml/element.rb index d04c2cf..b8fb16a 100644 --- a/lib/oga/xml/element.rb +++ b/lib/oga/xml/element.rb @@ -64,14 +64,14 @@ module Oga # # @return [Oga::XML::Attribute] def attribute(name) - if html? - ns = nil + name_str, ns = if html? + [name.to_s, nil] else - name, ns = split_name(name) + split_name(name) end attributes.each do |attr| - return attr if attribute_matches?(attr, ns, name) + return attr if attribute_matches?(attr, ns, name_str) end return @@ -115,10 +115,10 @@ module Oga if found found.value = value else - name, ns = split_name(name) + name_str, ns = split_name(name) attr = Attribute.new( - :name => name, + :name => name_str, :namespace_name => ns, :value => value ) diff --git a/spec/oga/xml/element_spec.rb b/spec/oga/xml/element_spec.rb index 1cf1a4f..fe7558f 100644 --- a/spec/oga/xml/element_spec.rb +++ b/spec/oga/xml/element_spec.rb @@ -107,13 +107,23 @@ describe Oga::XML::Element do end describe 'using an HTML document' do - it 'returns an attribute containing a namespace separator' do - attr = Oga::XML::Attribute.new(:name => 'foo:bar', :value => 'foo') - el = described_class.new(:name => 'foo', :attributes => [attr]) - doc = Oga::XML::Document.new(:children => [el], :type => :html) + let!(:attr) do + Oga::XML::Attribute.new(:name => 'foo:bar', :value => 'foo') + end + let!(:el) do + described_class.new(:name => 'foo', :attributes => [attr]) + end + let!(:doc) do + Oga::XML::Document.new(:children => [el], :type => :html) + end + it 'returns an attribute with a name containing a namespace separator' do el.attribute('foo:bar').should == attr end + + it 'returns an attribute with a name containing a namespace separator when using a Symbol' do + el.attribute(:'foo:bar').should == attr + end end end