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

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

Merge pull request #3123 from philipwhiuk/imgMap

Add support for image-maps
parents 26f6963e 3e647395
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");
+24 −0
Original line number Diff line number Diff line
@@ -177,6 +177,30 @@ 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=\"http://domain.com/sun.htm\" alt=\"Sun\">\n" +
                "  <area shape=\"circle\" coords=\"90,58,3\" href=\"http://domain.com/mercur.htm\" alt=\"Mercury\">\n" +
                "  <area shape=\"circle\" coords=\"124,58,8\" href=\"http://domain.com/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=\"http://domain.com/image.jpg\" usemap=\"#planetmap\">" +
                "</body></html>";

        Document result = htmlSanitizer.sanitize(html);

        assertEquals(html, toCompactString(result));
    }

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