EscapeTool extends org.apache.velocity.tools.generic.EscapeTool { public String css(String identifier) { try { return new CSSIdentifierSerializer().serialize(identifier); } catch (IllegalArgumentException e) { LOGGER.warn("Failed to escape CSS identifier. Root cause: [{}]", e.getMessage()); return null; } }  @Override String xml(Object content); String json(Object string); String quotedPrintable(Object content); String q(Object content); String b(Object content); String url(Map<String, ?> parametersMap); String css(String identifier); @Override String url(Object string);  }
@Test void css() { assertEquals("a\\#b\\.c\\ d\\[e\\=f\\]g\\{h\\:i\\;j\\}k", this.tool.css("a#b.c d[e=f]g{h:i;j}k")); assertNull(this.tool.css("a\u0000b")); assertEquals("Failed to escape CSS identifier. Root cause: [Invalid character: the input contains U+0000.]", this.logCapture.getMessage(0)); }