Keep 'align' attribute of 'div' elements

This commit is contained in:
cketti 2022-08-25 16:29:12 +02:00
parent 9cf73c99d0
commit 27d1dd3828
2 changed files with 19 additions and 0 deletions

View file

@ -15,6 +15,7 @@ internal class BodyCleaner {
val allowList = Safelist.relaxed()
.addTags("font", "hr", "ins", "del", "center", "map", "area", "title")
.addAttributes("font", "color", "face", "size")
.addAttributes("div", "align")
.addAttributes(
"table", "align", "background", "bgcolor", "border", "cellpadding", "cellspacing",
"width"

View file

@ -409,6 +409,24 @@ class HtmlSanitizerTest {
)
}
@Test
fun `should keep 'align' attribute on 'div' element`() {
val html = """<div align="center">text</div>"""
val result = htmlSanitizer.sanitize(html)
assertThat(result.toCompactString()).isEqualTo(
"""
<html>
<head></head>
<body>
<div align="center">text</div>
</body>
</html>
""".trimIndent().trimLineBreaks()
)
}
private fun Document.toCompactString(): String {
outputSettings()
.prettyPrint(false)