Merge pull request #3051 from philipwhiuk/testIframeUpdateJsoup

Html Sanitization: Update JSoup, test iframe removal & allow center
This commit is contained in:
cketti 2018-01-06 22:25:31 +01:00 committed by GitHub
commit c4c266c5ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

View file

@ -28,7 +28,7 @@ dependencies {
compile "com.squareup.okio:okio:${okioVersion}" compile "com.squareup.okio:okio:${okioVersion}"
compile 'commons-io:commons-io:2.4' compile 'commons-io:commons-io:2.4'
compile "com.android.support:support-v4:${androidSupportLibraryVersion}" compile "com.android.support:support-v4:${androidSupportLibraryVersion}"
compile 'org.jsoup:jsoup:1.10.2' compile 'org.jsoup:jsoup:1.11.2'
compile 'de.cketti.library.changelog:ckchangelog:1.2.1' compile 'de.cketti.library.changelog:ckchangelog:1.2.1'
compile 'com.github.bumptech.glide:glide:3.6.1' compile 'com.github.bumptech.glide:glide:3.6.1'
compile 'com.splitwise:tokenautocomplete:2.0.7' compile 'com.splitwise:tokenautocomplete:2.0.7'

View file

@ -13,7 +13,7 @@ public class HtmlSanitizer {
HtmlSanitizer() { HtmlSanitizer() {
Whitelist whitelist = Whitelist.relaxed() Whitelist whitelist = Whitelist.relaxed()
.addTags("font", "hr", "ins", "del") .addTags("font", "hr", "ins", "del", "center")
.addAttributes("font", "color", "face", "size") .addAttributes("font", "color", "face", "size")
.addAttributes("table", "align", "background", "bgcolor", "border", "cellpadding", "cellspacing", .addAttributes("table", "align", "background", "bgcolor", "border", "cellpadding", "cellspacing",
"width") "width")

View file

@ -189,4 +189,28 @@ public class HtmlSanitizerTest {
assertEquals("<html><head><style>keep this</style></head><body></body></html>", toCompactString(result)); assertEquals("<html><head><style>keep this</style></head><body></body></html>", toCompactString(result));
} }
@Test
public void shouldRemoveIFrames() {
String html = "<html><body>" +
"<iframe src=\"http://www.google.com\" />" +
"</body></html>";
Document result = htmlSanitizer.sanitize(html);
assertEquals("<html><head></head><body></body></html>", toCompactString(result));
}
@Test
public void shouldKeepFormattingTags() {
String html = "<html><body>" +
"<center><font face=\"Arial\" color=\"red\" size=\"12\">A</font></center>" +
"</body></html>";
Document result = htmlSanitizer.sanitize(html);
assertEquals("<html><head></head><body>" +
"<center><font face=\"Arial\" color=\"red\" size=\"12\">A</font></center>" +
"</body></html>", toCompactString(result));
}
} }