From 27d1dd38288dac5be0821ca419e95bf6eb708df7 Mon Sep 17 00:00:00 2001 From: cketti Date: Thu, 25 Aug 2022 16:29:12 +0200 Subject: [PATCH] Keep 'align' attribute of 'div' elements --- .../app/k9mail/html/cleaner/BodyCleaner.kt | 1 + .../k9mail/html/cleaner/HtmlSanitizerTest.kt | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt b/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt index 80fa043e8..2d9c493f9 100644 --- a/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt +++ b/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/BodyCleaner.kt @@ -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" diff --git a/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt b/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt index 12ea9e797..1faf36d2e 100644 --- a/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt +++ b/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt @@ -409,6 +409,24 @@ class HtmlSanitizerTest { ) } + @Test + fun `should keep 'align' attribute on 'div' element`() { + val html = """
text
""" + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo( + """ + + + +
text
+ + + """.trimIndent().trimLineBreaks() + ) + } + private fun Document.toCompactString(): String { outputSettings() .prettyPrint(false)