From 50ce5d5e6cd0d720ff437d35eace545816848428 Mon Sep 17 00:00:00 2001 From: "test@dangofactory.cos" Date: Thu, 20 Aug 2026 16:57:18 +0000 Subject: Inital --- .../app/k9mail/html/cleaner/HtmlSanitizerTest.kt | 516 +++++++++++++++++++++ 1 file changed, 516 insertions(+) create mode 100644 app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt (limited to 'app/html-cleaner/src/test/java') 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 new file mode 100644 index 0000000..f783e39 --- /dev/null +++ b/app/html-cleaner/src/test/java/app/k9mail/html/cleaner/HtmlSanitizerTest.kt @@ -0,0 +1,516 @@ +package app.k9mail.html.cleaner + +import assertk.assertThat +import assertk.assertions.isEqualTo +import org.jsoup.nodes.Document +import org.junit.Test + +class HtmlSanitizerTest { + private val htmlSanitizer = HtmlSanitizer() + + @Test + fun shouldRemoveMetaRefreshInHead() { + val html = + """ + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMetaRefreshBetweenHeadAndBody() { + val html = + """ + + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMetaRefreshInBody() { + val html = + """ + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMetaRefreshWithUpperCaseAttributeValue() { + val html = + """ + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMetaRefreshWithMixedCaseAttributeValue() { + val html = + """ + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMetaRefreshWithoutQuotesAroundAttributeValue() { + val html = + """ + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMetaRefreshWithSpacesInAttributeValue() { + val html = + """ + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMultipleMetaRefreshTags() { + val html = + """ + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("Message") + } + + @Test + fun shouldRemoveMetaRefreshButKeepOtherMetaTags() { + val html = + """ + + + + + + Message + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo( + """ + + + Message + + """.trimIndent().trimLineBreaks() + ) + } + + @Test + fun shouldProduceValidHtmlFromHtmlWithXmlDeclaration() { + val html = + """ + + + + + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("") + } + + @Test + fun shouldNormalizeTables() { + val html = "
" + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo( + "
" + ) + } + + @Test + fun shouldHtmlEncodeXmlDirectives() { + val html = + """ + + + +
Hmailserver service shutdown:Ok
+ + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo( + """ + + +
Hmailserver service shutdown:Ok
+ + """.trimIndent().trimLineBreaks() + ) + } + + @Test + fun shouldKeepHrTags() { + val html = "one
two
three" + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("one
two
three") + } + + @Test + fun shouldKeepInsDelTags() { + val html = "InsertedDeleted" + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo(html) + } + + @Test + fun shouldKeepMapAreaTags() { + val html = + """ + + + + + Sun + Mercury + Venus + + + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo(html) + } + + @Test + fun shouldKeepImgUsemap() { + val html = + """ + + + + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo(html) + } + + @Test + fun shouldKeepAllowedElementsInHeadAndSkipTheRest() { + val html = + """ + + + remove this + + + + + """.trimIndent().trimLineBreaks() + + val result = htmlSanitizer.sanitize(html) + + assertThat(result.toCompactString()).isEqualTo("") + } + + @Test + fun shouldRemoveIFrames() { + val html = """