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

Commit 4376f9bc authored by Philip Whitehouse's avatar Philip Whitehouse
Browse files

Add support for image-maps

parent 7c3b90b3
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@ public class HtmlSanitizer {

    HtmlSanitizer() {
        Whitelist whitelist = Whitelist.relaxed()
                .addTags("font", "hr", "ins", "del", "center")
                .addTags("font", "hr", "ins", "del", "center", "map", "area")
                .addAttributes("font", "color", "face", "size")
                .addAttributes("table", "align", "background", "bgcolor", "border", "cellpadding", "cellspacing",
                        "width")
@@ -24,6 +24,10 @@ public class HtmlSanitizer {
                .addAttributes("td",
                        "align", "bgcolor", "colspan", "headers", "height", "nowrap", "rowspan", "scope", "valign",
                        "width")
                .addAttributes("map", "name")
                .addAttributes("area", "shape", "coords", "href", "alt")
                .addProtocols("area", "href", "http", "https")
                .addAttributes("img", "usemap")
                .addAttributes(":all", "class", "style", "id")
                .addProtocols("img", "src", "http", "https", "cid", "data")
                .addProtocols("a", "href", "tel", "sip", "bitcoin", "ethereum", "rtsp");
+22 −0
Original line number Diff line number Diff line
@@ -177,6 +177,28 @@ public class HtmlSanitizerTest {
        assertEquals(html, toCompactString(result));
    }

    @Test
    public void shouldKeepMapAreaTags() {
        String html = "<html><head></head><body><map name=\"planetmap\">\n" +
                "  <area shape=\"rect\" coords=\"0,0,82,126\" href=\"sun.htm\" alt=\"Sun\">\n" +
                "  <area shape=\"circle\" coords=\"90,58,3\" href=\"mercur.htm\" alt=\"Mercury\">\n" +
                "  <area shape=\"circle\" coords=\"124,58,8\" href=\"venus.htm\" alt=\"Venus\">\n" +
                "</map></body></html>";

        Document result = htmlSanitizer.sanitize(html);

        assertEquals(html, toCompactString(result));
    }

    @Test
    public void shouldKeepImgUsemap() {
        String html = "<html><head></head><body><img src=\"image.jpg\" usemap=\"#planetmap\"></body></html>";

        Document result = htmlSanitizer.sanitize(html);

        assertEquals(html, toCompactString(result));
    }

    @Test
    public void shouldKeepWhitelistedElementsInHeadAndSkipTheRest() {
        String html = "<html><head>" +