parent
5182d0c488
commit
d0d597e2d9
|
@ -50,6 +50,10 @@ module Oga
|
|||
%w{thead tbody tfoot tr caption colgroup col}
|
||||
)
|
||||
|
||||
HTML_SCRIPT_ELEMENTS = Whitelist.new(%w{script template})
|
||||
|
||||
HTML_TABLE_ROW_ELEMENTS = Whitelist.new(%w{tr}) + HTML_SCRIPT_ELEMENTS
|
||||
|
||||
# Elements that should be closed automatically before a new opening tag is
|
||||
# processed.
|
||||
HTML_CLOSE_SELF = {
|
||||
|
@ -71,11 +75,11 @@ module Oga
|
|||
'option' => Blacklist.new(%w{optgroup option}),
|
||||
'colgroup' => Whitelist.new(%w{col template}),
|
||||
'caption' => HTML_TABLE_ALLOWED.to_blacklist,
|
||||
'table' => HTML_TABLE_ALLOWED,
|
||||
'thead' => Whitelist.new(%w{tr}),
|
||||
'tbody' => Whitelist.new(%w{tr}),
|
||||
'tfoot' => Whitelist.new(%w{tr}),
|
||||
'tr' => Whitelist.new(%w{td th}),
|
||||
'table' => HTML_TABLE_ALLOWED + HTML_SCRIPT_ELEMENTS,
|
||||
'thead' => HTML_TABLE_ROW_ELEMENTS,
|
||||
'tbody' => HTML_TABLE_ROW_ELEMENTS,
|
||||
'tfoot' => HTML_TABLE_ROW_ELEMENTS,
|
||||
'tr' => Whitelist.new(%w{td th}) + HTML_SCRIPT_ELEMENTS,
|
||||
'td' => Blacklist.new(%w{td th}) + HTML_TABLE_ALLOWED,
|
||||
'th' => Blacklist.new(%w{td th}) + HTML_TABLE_ALLOWED
|
||||
}
|
||||
|
|
|
@ -1,30 +1,46 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Oga::XML::Lexer do
|
||||
describe 'HTML tables' do
|
||||
describe 'with unclosed <tr> tags' do
|
||||
it 'lexes a <tr> tag followed by a <tbody> tag' do
|
||||
lex_html('<tr>foo<tbody></tbody>').should == [
|
||||
[:T_ELEM_NAME, 'tr', 1],
|
||||
describe 'using HTML <table> elements' do
|
||||
it 'lexes two unclosed <table> elements following each other as separate elements' do
|
||||
lex_html('<table>foo<table>bar').should == [
|
||||
[:T_ELEM_NAME, 'table', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_NAME, 'tbody', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes an unclosed <th> tag followed by a <tbody> tag' do
|
||||
lex_html('<tr><th>foo<tbody>bar</tbody>').should == [
|
||||
[:T_ELEM_NAME, 'tr', 1],
|
||||
[:T_ELEM_NAME, 'th', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_NAME, 'tbody', 1],
|
||||
[:T_ELEM_NAME, 'table', 1],
|
||||
[:T_TEXT, 'bar', 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <table> element containing a <thead> element' do
|
||||
lex_html('<table><thead>foo</thead></table>').should == [
|
||||
[:T_ELEM_NAME, 'table', 1],
|
||||
[:T_ELEM_NAME, 'thead', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <table> element containing a <script> element' do
|
||||
lex_html('<table><script>foo</script></table>').should == [
|
||||
[:T_ELEM_NAME, 'table', 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <table> element containing a <template> element' do
|
||||
lex_html('<table><template>foo</template></table>').should == [
|
||||
[:T_ELEM_NAME, 'table', 1],
|
||||
[:T_ELEM_NAME, 'template', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,5 +33,25 @@ describe Oga::XML::Lexer do
|
|||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <tbody> element containing a <script> element' do
|
||||
lex_html('<tbody><script>foo</script></tbody>').should == [
|
||||
[:T_ELEM_NAME, 'tbody', 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <tbody> element containing a <template> element' do
|
||||
lex_html('<tbody><template>foo</template></tbody>').should == [
|
||||
[:T_ELEM_NAME, 'tbody', 1],
|
||||
[:T_ELEM_NAME, 'template', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,5 +33,25 @@ describe Oga::XML::Lexer do
|
|||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <tfoot> element containing a <script> element' do
|
||||
lex_html('<tfoot><script>foo</script></tfoot>').should == [
|
||||
[:T_ELEM_NAME, 'tfoot', 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <tfoot> element containing a <template> element' do
|
||||
lex_html('<tfoot><template>foo</template></tfoot>').should == [
|
||||
[:T_ELEM_NAME, 'tfoot', 1],
|
||||
[:T_ELEM_NAME, 'template', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -33,5 +33,25 @@ describe Oga::XML::Lexer do
|
|||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <thead> element containing a <script> element' do
|
||||
lex_html('<thead><script>foo</script></thead>').should == [
|
||||
[:T_ELEM_NAME, 'thead', 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <thead> element containing a <template> element' do
|
||||
lex_html('<thead><template>foo</template></thead>').should == [
|
||||
[:T_ELEM_NAME, 'thead', 1],
|
||||
[:T_ELEM_NAME, 'template', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -32,5 +32,25 @@ describe Oga::XML::Lexer do
|
|||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <tr> element containing a <script> element' do
|
||||
lex_html('<tr><script>foo</script></tr>').should == [
|
||||
[:T_ELEM_NAME, 'tr', 1],
|
||||
[:T_ELEM_NAME, 'script', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
|
||||
it 'lexes a <tr> element containing a <template> element' do
|
||||
lex_html('<tr><template>foo</template></tr>').should == [
|
||||
[:T_ELEM_NAME, 'tr', 1],
|
||||
[:T_ELEM_NAME, 'template', 1],
|
||||
[:T_TEXT, 'foo', 1],
|
||||
[:T_ELEM_END, nil, 1],
|
||||
[:T_ELEM_END, nil, 1]
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue