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

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

Merge pull request #7180 from thundernest/keep_style_element

Allow `<style>` tags inside the HTML body
parents 5489a2c8 5bf877f5
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ internal class BodyCleaner {

    init {
        val allowList = Safelist.relaxed()
            .addTags("font", "hr", "ins", "del", "center", "map", "area", "title", "tt", "kbd", "samp", "var")
            .addTags("font", "hr", "ins", "del", "center", "map", "area", "title", "tt", "kbd", "samp", "var", "style")
            .addAttributes("font", "color", "face", "size")
            .addAttributes("a", "name")
            .addAttributes("div", "align")
+17 −0
Original line number Diff line number Diff line
@@ -485,6 +485,23 @@ class HtmlSanitizerTest {
        assertThat(result.toCompactString()).isEqualTo(html)
    }

    @Test
    fun `should keep 'style' element in body`() {
        val html =
            """
            <html>
              <head></head>
              <body>
                <style>.test { color: #000 }</style>
              </body>
            </html>
            """.compactHtml()

        val result = htmlSanitizer.sanitize(html)

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

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