URLFragment implements Fragment { boolean isValidURL(String url) { if (Strings.isBlank(url)) return false; if (url.contains("javascript:")) return false; int length = url.length(); for (int i = 0; i < length; i++) { char ch = url.charAt(i); if (!VALID_URI.get(ch)) return false; } return true; } URLFragment(String expression, TemplateMetaContext context, boolean cdn, String location); @Override void process(StringBuilder builder, TemplateContext context);  }
@Test void isValidURL() { String protocolRelativeURL = " assertThat(fragment.isValidURL(protocolRelativeURL)).isTrue(); String httpsURL = "http: assertThat(fragment.isValidURL(httpsURL)).isTrue(); String dataImageURL = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 assertThat(fragment.isValidURL(dataImageURL)).isTrue(); assertFalse(fragment.isValidURL(null)); }