@Bean public HerdCharacterEscapeHandler herdCharacterEscapeHandler() { return new HerdCharacterEscapeHandler(); }
@Test public void testEscapeNoAttribute() throws Exception { // "No attribute" doesn't escape double and single quotes. StringWriter writer = new StringWriter(); escapeHandler.escape(TEST_BUFFER.toCharArray(), 0, TEST_BUFFER.length(), false, writer); assertEquals("A<>&\"'\t", writer.toString()); }
@Test public void testEscapeAttribute() throws Exception { // "Attribute" escapes double and single quotes. StringWriter writer = new StringWriter(); escapeHandler.escape(TEST_BUFFER.toCharArray(), 0, TEST_BUFFER.length(), true, writer); assertEquals("A<>&"'\t", writer.toString()); }
@Test public void testEscapeSubBuffer() throws Exception { // Test a sub-part of the buffer (i.e. positions 1 and 2). StringWriter writer = new StringWriter(); escapeHandler.escape(TEST_BUFFER.toCharArray(), 1, 2, true, writer); assertEquals("<>", writer.toString()); } }