diff --git a/lib/oga/css/parser.y b/lib/oga/css/parser.y index e113b2c..54ca342 100644 --- a/lib/oga/css/parser.y +++ b/lib/oga/css/parser.y @@ -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]) ) } diff --git a/spec/oga/css/parser/classes_spec.rb b/spec/oga/css/parser/classes_spec.rb index 7cf0289..9bb421d 100644 --- a/spec/oga/css/parser/classes_spec.rb +++ b/spec/oga/css/parser/classes_spec.rb @@ -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 diff --git a/spec/oga/css/parser/ids_spec.rb b/spec/oga/css/parser/ids_spec.rb index cc6ef6a..42876b0 100644 --- a/spec/oga/css/parser/ids_spec.rb +++ b/spec/oga/css/parser/ids_spec.rb @@ -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