Fix using symbol on Element#attribute alwas getting nil
This commit is contained in:
parent
e9953d4212
commit
21b5eeec4b
|
@ -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
|
||||
)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in New Issue