Merge pull request #7180 from thundernest/keep_style_element

Allow `<style>` tags inside the HTML body
This commit is contained in:
cketti 2023-09-20 13:17:18 +02:00 committed by GitHub
commit df1231d780
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -13,7 +13,7 @@ internal class BodyCleaner {
init {
val allowList = Safelist.relaxed()
.addTags("font", "hr", "ins", "del", "center", "map", "area", "title", "tt", "kbd", "samp", "var")
.addTags("font", "hr", "ins", "del", "center", "map", "area", "title", "tt", "kbd", "samp", "var", "style")
.addAttributes("font", "color", "face", "size")
.addAttributes("a", "name")
.addAttributes("div", "align")

View file

@ -485,6 +485,23 @@ class HtmlSanitizerTest {
assertThat(result.toCompactString()).isEqualTo(html)
}
@Test
fun `should keep 'style' element in body`() {
val html =
"""
<html>
<head></head>
<body>
<style>.test { color: #000 }</style>
</body>
</html>
""".compactHtml()
val result = htmlSanitizer.sanitize(html)
assertThat(result.toCompactString()).isEqualTo(html)
}
private fun assertTagsNotStripped(element: String) {
val html = """<$element>some text</$element>"""