@Test public void isSafe() { HtmlSanitizer.SanitizeInfos sanitizeInfos = HtmlSanitizer.isSafe(getSafe()); assertTrue(sanitizeInfos.isSafe()); assertEquals("[]", sanitizeInfos.getRejectedMessage()); }
public static SanitizeInfos isSafe(String content) { if (content == null || content.isEmpty()) { return new SanitizeInfos(true); } String toSanitize = htmlRenderer.render(mdParser.parse(content)); List<String> sanitizedChanges = new ArrayList<>(); HtmlChangeListener<List<String>> listener = new HtmlChangeListener<List<String>>() { @Override public void discardedTag(@Nullable List<String> context, String elementName) { context.add("Tag not allowed: " + elementName); } @Override public void discardedAttributes(@Nullable List<String> context, String tagName, String... attributeNames) { context.add("Attribute not allowed: [" + tagName + "]" + Arrays.toString(attributeNames)); } }; HtmlSanitizer.sanitize(toSanitize, listener, sanitizedChanges); return new SanitizeInfos(sanitizedChanges.isEmpty(), sanitizedChanges.toString()); }
HtmlSanitizer { public static SanitizeInfos isSafe(String content) { if (content == null || content.isEmpty()) { return new SanitizeInfos(true); } String toSanitize = htmlRenderer.render(mdParser.parse(content)); List<String> sanitizedChanges = new ArrayList<>(); HtmlChangeListener<List<String>> listener = new HtmlChangeListener<List<String>>() { @Override public void discardedTag(@Nullable List<String> context, String elementName) { context.add("Tag not allowed: " + elementName); } @Override public void discardedAttributes(@Nullable List<String> context, String tagName, String... attributeNames) { context.add("Attribute not allowed: [" + tagName + "]" + Arrays.toString(attributeNames)); } }; HtmlSanitizer.sanitize(toSanitize, listener, sanitizedChanges); return new SanitizeInfos(sanitizedChanges.isEmpty(), sanitizedChanges.toString()); } }
HtmlSanitizer { public static SanitizeInfos isSafe(String content) { if (content == null || content.isEmpty()) { return new SanitizeInfos(true); } String toSanitize = htmlRenderer.render(mdParser.parse(content)); List<String> sanitizedChanges = new ArrayList<>(); HtmlChangeListener<List<String>> listener = new HtmlChangeListener<List<String>>() { @Override public void discardedTag(@Nullable List<String> context, String elementName) { context.add("Tag not allowed: " + elementName); } @Override public void discardedAttributes(@Nullable List<String> context, String tagName, String... attributeNames) { context.add("Attribute not allowed: [" + tagName + "]" + Arrays.toString(attributeNames)); } }; HtmlSanitizer.sanitize(toSanitize, listener, sanitizedChanges); return new SanitizeInfos(sanitizedChanges.isEmpty(), sanitizedChanges.toString()); } private  HtmlSanitizer(); }
HtmlSanitizer { public static SanitizeInfos isSafe(String content) { if (content == null || content.isEmpty()) { return new SanitizeInfos(true); } String toSanitize = htmlRenderer.render(mdParser.parse(content)); List<String> sanitizedChanges = new ArrayList<>(); HtmlChangeListener<List<String>> listener = new HtmlChangeListener<List<String>>() { @Override public void discardedTag(@Nullable List<String> context, String elementName) { context.add("Tag not allowed: " + elementName); } @Override public void discardedAttributes(@Nullable List<String> context, String tagName, String... attributeNames) { context.add("Attribute not allowed: [" + tagName + "]" + Arrays.toString(attributeNames)); } }; HtmlSanitizer.sanitize(toSanitize, listener, sanitizedChanges); return new SanitizeInfos(sanitizedChanges.isEmpty(), sanitizedChanges.toString()); } private  HtmlSanitizer(); static String sanitize(String content); static String sanitize(String content, HtmlChangeListener<CTX> listener, CTX context); static SanitizeInfos isSafe(String content); }
HtmlSanitizer { public static SanitizeInfos isSafe(String content) { if (content == null || content.isEmpty()) { return new SanitizeInfos(true); } String toSanitize = htmlRenderer.render(mdParser.parse(content)); List<String> sanitizedChanges = new ArrayList<>(); HtmlChangeListener<List<String>> listener = new HtmlChangeListener<List<String>>() { @Override public void discardedTag(@Nullable List<String> context, String elementName) { context.add("Tag not allowed: " + elementName); } @Override public void discardedAttributes(@Nullable List<String> context, String tagName, String... attributeNames) { context.add("Attribute not allowed: [" + tagName + "]" + Arrays.toString(attributeNames)); } }; HtmlSanitizer.sanitize(toSanitize, listener, sanitizedChanges); return new SanitizeInfos(sanitizedChanges.isEmpty(), sanitizedChanges.toString()); } private  HtmlSanitizer(); static String sanitize(String content); static String sanitize(String content, HtmlChangeListener<CTX> listener, CTX context); static SanitizeInfos isSafe(String content);  }