diff --git a/lib/oga/lexer.rl b/lib/oga/lexer.rl index 1f4675d..66f7de5 100644 --- a/lib/oga/lexer.rl +++ b/lib/oga/lexer.rl @@ -302,9 +302,17 @@ module Oga element_name %{ t(:T_ATTR, @ts, p) - advance_column } - '=' (dquote @string_dquote | squote @string_squote); + + # The value of the attribute. Attribute values are not required. e.g. + # in

data-foo would be a boolean attribute. + ( + '=' >{ advance_column } + + # The value of the attribute, wrapped in either single or double + # quotes. + (dquote @string_dquote | squote @string_squote) + )*; # Non self-closing elements. ' { diff --git a/spec/oga/lexer/elements_spec.rb b/spec/oga/lexer/elements_spec.rb index 467cda1..a7deee5 100644 --- a/spec/oga/lexer/elements_spec.rb +++ b/spec/oga/lexer/elements_spec.rb @@ -25,6 +25,17 @@ describe Oga::Lexer do [:T_ELEM_CLOSE, nil, 1, 9] ] end + end + + context 'elements with attributes' do + example 'lex an element with an attribute without a value' do + lex('

').should == [ + [:T_ELEM_OPEN, nil, 1, 1], + [:T_ELEM_NAME, 'p', 1, 2], + [:T_ATTR, 'foo', 1, 4], + [:T_ELEM_CLOSE, nil, 1, 8] + ] + end example 'lex a paragraph element with attributes' do lex('

Hello

').should == [