Merge pull request #3123 from philipwhiuk/imgMap

Add support for image-maps
This commit is contained in:
cketti 2018-01-25 23:42:03 +01:00 committed by GitHub
commit affc41c853
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 1 deletions

View file

@ -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");

View file

@ -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>" +