Fixes #129 - lexing superfluous end tags.

Prevents a superfluous end tag of a self-closing HTML tag from
closing its parent element prematurely, for example:

```html
<object><param></param><param></param></object>
```

(note <param> is self closing) being turned into:

```html
<object><param/></object><param/>
```
This commit is contained in:
Jakub Pawlowicz 2015-07-23 12:40:32 +01:00
parent d69be182bd
commit ed3cbe7975
2 changed files with 15 additions and 1 deletions

View File

@ -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

View File

@ -9,5 +9,16 @@ describe Oga::XML::Lexer do
[:T_ELEM_END, nil, 1]
]
end
it 'lexes a <param> element' do
lex_html('<object><param></param><param></param></object>').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