Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 14c5c07e authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #6588 from thundernest/keep_base_element

Keep `<base>` element
parents f3ac66e6 ef2b955d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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) {
+21 −0
Original line number Diff line number Diff line
@@ -465,6 +465,25 @@ class HtmlSanitizerTest {
        assertTagsNotStripped("var")
    }

    @Test
    fun `should keep 'base' element`() {
        val html =
            """
            <html>
              <head>
                <base href="https://domain.example/">
              </head>
              <body>
                <a href="relative">Link</a>
              </body>
            </html>
            """.compactHtml()

        val result = htmlSanitizer.sanitize(html)

        assertThat(result.toCompactString()).isEqualTo(html)
    }

    private fun assertTagsNotStripped(element: String) {
        val html = """<$element>some text</$element>"""

@@ -491,4 +510,6 @@ class HtmlSanitizerTest {
    }

    private fun String.trimLineBreaks() = replace("\n", "")

    private fun String.compactHtml() = lines().joinToString(separator = "") { it.trim() }
}