Allow "th" to occur in thead, tbody, and tfoot

Fixes https://gitlab.com/yorickpeterse/oga/issues/190
This commit is contained in:
Yorick Peterse 2018-04-11 21:29:40 +02:00
parent 6c10f41446
commit 8ac0055e42
No known key found for this signature in database
GPG Key ID: EDD30D2BEB691AC9
4 changed files with 35 additions and 1 deletions

View File

@ -58,7 +58,11 @@ module Oga
HTML_SCRIPT_ELEMENTS = Whitelist.new(%w{script template}) HTML_SCRIPT_ELEMENTS = Whitelist.new(%w{script template})
HTML_TABLE_ROW_ELEMENTS = Whitelist.new(%w{tr}) + HTML_SCRIPT_ELEMENTS # The elements that may occur in a thead, tbody, or tfoot.
#
# Technically "th" is not allowed per the HTML5 spec, but it's so commonly
# used in these elements that we allow it anyway.
HTML_TABLE_ROW_ELEMENTS = Whitelist.new(%w{tr th}) + HTML_SCRIPT_ELEMENTS
# Elements that should be closed automatically before a new opening tag is # Elements that should be closed automatically before a new opening tag is
# processed. # processed.

View File

@ -53,5 +53,15 @@ describe Oga::XML::Lexer do
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
]) ])
end end
it 'lexes a <tbody> element containing a <th> element' do
expect(lex_html('<tbody><th>foo</th></tbody>')).to eq([
[:T_ELEM_NAME, 'tbody', 1],
[:T_ELEM_NAME, 'th', 1],
[:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1]
])
end
end end
end end

View File

@ -53,5 +53,15 @@ describe Oga::XML::Lexer do
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
]) ])
end end
it 'lexes a <tfoot> element containing a <th> element' do
expect(lex_html('<tfoot><th>foo</th></tfoot>')).to eq([
[:T_ELEM_NAME, 'tfoot', 1],
[:T_ELEM_NAME, 'th', 1],
[:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1]
])
end
end end
end end

View File

@ -53,5 +53,15 @@ describe Oga::XML::Lexer do
[:T_ELEM_END, nil, 1] [:T_ELEM_END, nil, 1]
]) ])
end end
it 'lexes a <thead> element containing a <th> element' do
expect(lex_html('<thead><th>foo</th></thead>')).to eq([
[:T_ELEM_NAME, 'thead', 1],
[:T_ELEM_NAME, 'th', 1],
[:T_TEXT, 'foo', 1],
[:T_ELEM_END, nil, 1],
[:T_ELEM_END, nil, 1]
])
end
end end
end end