@Test public void testCleanAnchorProtocol() { String validAnchor = "<a href=\"#valid\">Valid anchor</a>"; String invalidAnchor = "<a href=\"#anchor with spaces\">Invalid anchor</a>"; String cleanHtml = Jsoup.clean(validAnchor, Whitelist.relaxed()); assertEquals("<a>Valid anchor</a>", cleanHtml); cleanHtml = Jsoup.clean(invalidAnchor, Whitelist.relaxed()); assertEquals("<a>Invalid anchor</a>", cleanHtml); Whitelist relaxedWithAnchor = Whitelist.relaxed().addProtocols("a", "href", "#"); cleanHtml = Jsoup.clean(validAnchor, relaxedWithAnchor); assertEquals(validAnchor, cleanHtml); cleanHtml = Jsoup.clean(invalidAnchor, relaxedWithAnchor); assertEquals("<a>Invalid anchor</a>", cleanHtml); }
public Document clean(Document dirtyDocument) { Validate.notNull(dirtyDocument); Document clean = Document.createShell(dirtyDocument.baseUri()); if (dirtyDocument.body() != null) copySafeNodes(dirtyDocument.body(), clean.body()); return clean; }
Cleaner { public Document clean(Document dirtyDocument) { Validate.notNull(dirtyDocument); Document clean = Document.createShell(dirtyDocument.baseUri()); if (dirtyDocument.body() != null) copySafeNodes(dirtyDocument.body(), clean.body()); return clean; } }
Cleaner { public Document clean(Document dirtyDocument) { Validate.notNull(dirtyDocument); Document clean = Document.createShell(dirtyDocument.baseUri()); if (dirtyDocument.body() != null) copySafeNodes(dirtyDocument.body(), clean.body()); return clean; } Cleaner(Whitelist whitelist); }
Cleaner { public Document clean(Document dirtyDocument) { Validate.notNull(dirtyDocument); Document clean = Document.createShell(dirtyDocument.baseUri()); if (dirtyDocument.body() != null) copySafeNodes(dirtyDocument.body(), clean.body()); return clean; } Cleaner(Whitelist whitelist); Document clean(Document dirtyDocument); boolean isValid(Document dirtyDocument); boolean isValidBodyHtml(String bodyHtml); }
Cleaner { public Document clean(Document dirtyDocument) { Validate.notNull(dirtyDocument); Document clean = Document.createShell(dirtyDocument.baseUri()); if (dirtyDocument.body() != null) copySafeNodes(dirtyDocument.body(), clean.body()); return clean; } Cleaner(Whitelist whitelist); Document clean(Document dirtyDocument); boolean isValid(Document dirtyDocument); boolean isValidBodyHtml(String bodyHtml);  }