From ef2b955d01efb048ad2d5436171a6c9bc3ff5bd8 Mon Sep 17 00:00:00 2001 From: cketti Date: Tue, 17 Jan 2023 16:23:18 +0100 Subject: [PATCH] Keep `` element --- .../app/k9mail/html/cleaner/HeadCleaner.kt | 2 +- .../k9mail/html/cleaner/HtmlSanitizerTest.kt | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/HeadCleaner.kt b/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/HeadCleaner.kt index d9ac70f81..148529142 100644 --- a/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/HeadCleaner.kt +++ b/app/html-cleaner/src/main/java/app/k9mail/html/cleaner/HeadCleaner.kt @@ -9,7 +9,7 @@ import org.jsoup.parser.Tag import org.jsoup.select.NodeTraversor import org.jsoup.select.NodeVisitor -private val ALLOWED_TAGS = listOf("style", "meta") +private val ALLOWED_TAGS = listOf("style", "meta", "base") internal class HeadCleaner { fun clean(dirtyDocument: Document, cleanedDocument: Document) { 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 d60ae8b38..902500006 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 @@ -465,6 +465,25 @@ class HtmlSanitizerTest { assertTagsNotStripped("var") } + @Test + fun `should keep 'base' element`() { + val html = + """ + + + + + + Link + + + """.compactHtml() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo(html) + } + private fun assertTagsNotStripped(element: String) { val html = """<$element>some text""" @@ -491,4 +510,6 @@ class HtmlSanitizerTest { } private fun String.trimLineBreaks() = replace("\n", "") + + private fun String.compactHtml() = lines().joinToString(separator = "") { it.trim() } }