Merge pull request #7180 from thundernest/keep_style_element
Allow `<style>` tags inside the HTML body
This commit is contained in:
commit
df1231d780
2 changed files with 18 additions and 1 deletions
|
@ -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")
|
||||
|
|
|
@ -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>"""
|
||||
|
||||
|
|
Loading…
Reference in a new issue