Skip to content

Commit a83e505

Browse files
committed
Whitelist summary and details element.
And details needs an open attribute Ref. https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
1 parent 45d6b4d commit a83e505

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/html/pipeline/sanitization_filter.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class SanitizationFilter < Filter
4545
:elements => %w(
4646
h1 h2 h3 h4 h5 h6 h7 h8 br b i strong em a pre code img tt
4747
div ins del sup sub p ol ul table thead tbody tfoot blockquote
48-
dl dt dd kbd q samp var hr ruby rt rp li tr td th s strike
48+
dl dt dd kbd q samp var hr ruby rt rp li tr td th s strike summary details
4949
),
5050
:remove_contents => ['script'],
5151
:attributes => {
@@ -57,13 +57,13 @@ class SanitizationFilter < Filter
5757
'border', 'cellpadding', 'cellspacing', 'char',
5858
'charoff', 'charset', 'checked', 'cite',
5959
'clear', 'cols', 'colspan', 'color',
60-
'compact', 'coords', 'datetime', 'details', 'dir',
60+
'compact', 'coords', 'datetime', 'dir',
6161
'disabled', 'enctype', 'for', 'frame',
6262
'headers', 'height', 'hreflang',
6363
'hspace', 'ismap', 'label', 'lang',
6464
'longdesc', 'maxlength', 'media', 'method',
6565
'multiple', 'name', 'nohref', 'noshade',
66-
'nowrap', 'prompt', 'readonly', 'rel', 'rev',
66+
'nowrap', 'open', 'prompt', 'readonly', 'rel', 'rev',
6767
'rows', 'rowspan', 'rules', 'scope',
6868
'selected', 'shape', 'size', 'span',
6969
'start', 'summary', 'tabindex', 'target',

test/html/pipeline/sanitization_filter_test.rb

+24
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,28 @@ def test_table_sections_are_not_removed
127127
</table>)
128128
assert_equal orig, SanitizationFilter.call(orig).to_s
129129
end
130+
131+
def test_summary_tag_are_not_removed
132+
orig = %(<summary>Foo</summary>)
133+
assert_equal orig, SanitizationFilter.call(orig).to_s
134+
end
135+
136+
def test_details_tag_and_open_attribute_are_not_removed
137+
orig = %(<details open>Foo</details>)
138+
assert_equal orig, SanitizationFilter.call(orig).to_s
139+
end
140+
141+
def test_nested_details_tag_are_not_removed
142+
orig = <<-NESTED
143+
<details>
144+
<summary>Foo</summary>
145+
<details>
146+
Bar
147+
<summary>Baz</summary>
148+
</details>
149+
Qux
150+
</details>
151+
NESTED
152+
assert_equal orig, SanitizationFilter.call(orig).to_s
153+
end
130154
end

0 commit comments

Comments
 (0)