Add support for image-maps
This commit is contained in:
parent
7c3b90b356
commit
4376f9bc22
2 changed files with 27 additions and 1 deletions
|
@ -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");
|
||||
|
|
|
@ -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>" +
|
||||
|
|
Loading…
Reference in a new issue