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]
|
# @return [Oga::XML::Attribute]
|
||||||
def attribute(name)
|
def attribute(name)
|
||||||
if html?
|
name_str, ns = if html?
|
||||||
ns = nil
|
[name.to_s, nil]
|
||||||
else
|
else
|
||||||
name, ns = split_name(name)
|
split_name(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
attributes.each do |attr|
|
attributes.each do |attr|
|
||||||
return attr if attribute_matches?(attr, ns, name)
|
return attr if attribute_matches?(attr, ns, name_str)
|
||||||
end
|
end
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -115,10 +115,10 @@ module Oga
|
||||||
if found
|
if found
|
||||||
found.value = value
|
found.value = value
|
||||||
else
|
else
|
||||||
name, ns = split_name(name)
|
name_str, ns = split_name(name)
|
||||||
|
|
||||||
attr = Attribute.new(
|
attr = Attribute.new(
|
||||||
:name => name,
|
:name => name_str,
|
||||||
:namespace_name => ns,
|
:namespace_name => ns,
|
||||||
:value => value
|
:value => value
|
||||||
)
|
)
|
||||||
|
|
|
@ -107,13 +107,23 @@ describe Oga::XML::Element do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'using an HTML document' do
|
describe 'using an HTML document' do
|
||||||
it 'returns an attribute containing a namespace separator' do
|
let!(:attr) do
|
||||||
attr = Oga::XML::Attribute.new(:name => 'foo:bar', :value => 'foo')
|
Oga::XML::Attribute.new(:name => 'foo:bar', :value => 'foo')
|
||||||
el = described_class.new(:name => 'foo', :attributes => [attr])
|
end
|
||||||
doc = Oga::XML::Document.new(:children => [el], :type => :html)
|
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
|
el.attribute('foo:bar').should == attr
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue