@Test public void testCdata() { Engine engine = Engine.builder().addDefaults().build(); String jsSnippet = "<script>const foo = function(){alert('bar');};</script>"; try { engine.parse("Hello {name} " + jsSnippet); fail(); } catch (Exception expected) { } assertEquals("Hello world <script>const foo = function(){alert('bar');};</script>", engine.parse("Hello {name} {[" + jsSnippet + "]}").data("name", "world").render()); assertEquals("Hello world <strong>", engine.parse("Hello {name} {[<strong>]}").data("name", "world").render()); assertEquals("Hello world <script>const foo = function(){alert('bar');};</script>", engine.parse("Hello {name} {|" + jsSnippet + "|}").data("name", "world").render()); assertEquals("Hello world <strong>", engine.parse("Hello {name} {|<strong>|}").data("name", "world").render()); assertEquals("Hello {name} world", engine.parse("Hello{| {name} |}{name}").data("name", "world").render()); }
private void cdata(char character) { if (character == END_DELIMITER && buffer.length() > 0 && isCdataEnd(buffer.charAt(buffer.length() - 1))) { state = State.TEXT; buffer.deleteCharAt(buffer.length() - 1); flushText(); } else { buffer.append(character); } }
Parser implements Function<String, Expression>, ParserHelper { private void cdata(char character) { if (character == END_DELIMITER && buffer.length() > 0 && isCdataEnd(buffer.charAt(buffer.length() - 1))) { state = State.TEXT; buffer.deleteCharAt(buffer.length() - 1); flushText(); } else { buffer.append(character); } } }
Parser implements Function<String, Expression>, ParserHelper { private void cdata(char character) { if (character == END_DELIMITER && buffer.length() > 0 && isCdataEnd(buffer.charAt(buffer.length() - 1))) { state = State.TEXT; buffer.deleteCharAt(buffer.length() - 1); flushText(); } else { buffer.append(character); } } Parser(EngineImpl engine); }
Parser implements Function<String, Expression>, ParserHelper { private void cdata(char character) { if (character == END_DELIMITER && buffer.length() > 0 && isCdataEnd(buffer.charAt(buffer.length() - 1))) { state = State.TEXT; buffer.deleteCharAt(buffer.length() - 1); flushText(); } else { buffer.append(character); } } Parser(EngineImpl engine); @Override ExpressionImpl apply(String value); @Override void addParameter(String name, String type); }
Parser implements Function<String, Expression>, ParserHelper { private void cdata(char character) { if (character == END_DELIMITER && buffer.length() > 0 && isCdataEnd(buffer.charAt(buffer.length() - 1))) { state = State.TEXT; buffer.deleteCharAt(buffer.length() - 1); flushText(); } else { buffer.append(character); } } Parser(EngineImpl engine); @Override ExpressionImpl apply(String value); @Override void addParameter(String name, String type);  }