@Test public void testEscapeXml() { assertEquals("abcd", StringUtils.escapeXml("abcd")); assertEquals( "a<table border="0" color='red'>b&lt;c</table>d", StringUtils.escapeXml("a<table border=\"0\" color=\'red\'>b<c</table>d")); }
@Test public void testEscapeXmlPerformance() { String html = "a<table border=\"0\" color=\'red\'>b<c</table>d"; // char[] html = "a<table border=\"0\" color=\'red\'>b<c</table>d".toCharArray(); int count = profile ? 10 * 1000 * 1000 : 1000; long start = System.nanoTime(); for (int i = 0; i < count; i++) { StringUtils.escapeXml(html); } long elapsed = System.nanoTime() - start; DecimalFormat format = new DecimalFormat("###,##0.###"); System.out.println( "elapsed: " + format.format(elapsed) + "ns, tps: " + format.format(1000L * 1000L * 1000L * (long) count / elapsed)); }
public byte[] filter(String key, byte[] value) { return StringUtils.escapeXml(value); }
public char[] filter(String key, char[] value) { return StringUtils.escapeXml(value); }
public String filter(String key, String value) { return StringUtils.escapeXml(value); }
@Test public void escapeXmlBytes() { assertEquals("中<文>字"符", new String(StringUtils.escapeXml("中<文>字\"符".getBytes()))); }