Fixed parsing of CSS class selectors.
When a class selector is used it should be checked as one of the possible values, not as _the_ only value (unlike ID selectors).
This commit is contained in:
parent
174d33c597
commit
15ebdb7de4
|
@ -97,9 +97,12 @@ rule
|
|||
class
|
||||
: T_DOT T_IDENT
|
||||
{
|
||||
axis = s(:axis, 'attribute', s(:test, nil, 'class'))
|
||||
|
||||
s(
|
||||
:eq,
|
||||
s(:axis, 'attribute', s(:test, nil, 'class')),
|
||||
:call,
|
||||
'contains',
|
||||
s(:call, 'concat', s(:string, ' '), axis, s(:string, ' ')),
|
||||
s(:string, val[1])
|
||||
)
|
||||
}
|
||||
|
|
|
@ -4,25 +4,27 @@ describe Oga::CSS::Parser do
|
|||
context 'classes' do
|
||||
example 'parse a class selector' do
|
||||
parse_css('.foo').should == parse_xpath(
|
||||
'descendant-or-self::*[@class="foo"]'
|
||||
'descendant-or-self::*[contains(concat(" ", @class, " "), "foo")]'
|
||||
)
|
||||
end
|
||||
|
||||
example 'parse a selector for an element with a class' do
|
||||
parse_css('foo.bar').should == parse_xpath(
|
||||
'descendant-or-self::foo[@class="bar"]'
|
||||
'descendant-or-self::foo[contains(concat(" ", @class, " "), "bar")]'
|
||||
)
|
||||
end
|
||||
|
||||
example 'parse a selector using multiple classes' do
|
||||
parse_css('.foo.bar').should == parse_xpath(
|
||||
'descendant-or-self::*[@class="foo" and @class="bar"]'
|
||||
'descendant-or-self::*[contains(concat(" ", @class, " "), "foo") ' \
|
||||
'and contains(concat(" ", @class, " "), "bar")]'
|
||||
)
|
||||
end
|
||||
|
||||
example 'parse a selector using a class and an ID' do
|
||||
parse_css('#foo.bar').should == parse_xpath(
|
||||
'descendant-or-self::*[@id="foo" and @class="bar"]'
|
||||
'descendant-or-self::*[@id="foo" and ' \
|
||||
'contains(concat(" ", @class, " "), "bar")]'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -22,7 +22,8 @@ describe Oga::CSS::Parser do
|
|||
|
||||
example 'parse a selector using an ID and a class' do
|
||||
parse_css('.foo#bar').should == parse_xpath(
|
||||
'descendant-or-self::*[@class="foo" and @id="bar"]'
|
||||
'descendant-or-self::*[contains(concat(" ", @class, " "), "foo") ' \
|
||||
'and @id="bar"]'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue