diff --git a/lib/oga/xml/lexer.rb b/lib/oga/xml/lexer.rb index 001a1f5..8ffc830 100644 --- a/lib/oga/xml/lexer.rb +++ b/lib/oga/xml/lexer.rb @@ -512,8 +512,11 @@ module Oga end end - add_token(:T_ELEM_END) + # Prevents a superfluous end tag of a self-closing HTML tag from + # closing its parent element prematurely + return if html? && name && name != current_element + add_token(:T_ELEM_END) @elements.pop end diff --git a/spec/oga/html/lexer/closing_mismatch_spec.rb b/spec/oga/html/lexer/closing_mismatch_spec.rb index f177745..5cabc4e 100644 --- a/spec/oga/html/lexer/closing_mismatch_spec.rb +++ b/spec/oga/html/lexer/closing_mismatch_spec.rb @@ -9,5 +9,16 @@ describe Oga::XML::Lexer do [:T_ELEM_END, nil, 1] ] end + + it 'lexes a element' do + lex_html('').should == [ + [:T_ELEM_NAME, 'object', 1], + [:T_ELEM_NAME, 'param', 1], + [:T_ELEM_END, nil, 1], + [:T_ELEM_NAME, 'param', 1], + [:T_ELEM_END, nil, 1], + [:T_ELEM_END, nil, 1] + ] + end end end