From 4e144d86b6874e2236a0dbb575b6c2708ef6f71b Mon Sep 17 00:00:00 2001 From: Jack Smith Date: Tue, 3 Sep 2024 18:47:55 -0400 Subject: [PATCH] Test that parse errors are ignored when doing nested interpretation --- .../jinjava/tree/ExpressionNodeTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/test/java/com/hubspot/jinjava/tree/ExpressionNodeTest.java b/src/test/java/com/hubspot/jinjava/tree/ExpressionNodeTest.java index 12a24c04c..23b482228 100644 --- a/src/test/java/com/hubspot/jinjava/tree/ExpressionNodeTest.java +++ b/src/test/java/com/hubspot/jinjava/tree/ExpressionNodeTest.java @@ -236,6 +236,28 @@ public void itEscapesValueWhenContextSet() throws Exception { assertThat(val("{{ a }}")).isEqualTo("foo < bar"); } + @Test + public void itIgnoresParseErrorsWhenFeatureIsEnabled() { + final JinjavaConfig config = JinjavaConfig + .newBuilder() + .withFeatureConfig( + FeatureConfig + .newBuilder() + .add(JinjavaInterpreter.IGNORE_NESTED_INTERPRETATION_PARSE_ERRORS, c -> true) + .build() + ) + .build(); + JinjavaInterpreter interpreter = new Jinjava(config).newInterpreter(); + Context context = interpreter.getContext(); + context.put("myvar", "hello {% if"); + context.put("place", "world"); + + ExpressionNode node = fixture("simplevar"); + + assertThat(node.render(interpreter).toString()).isEqualTo("hello {% if"); + assertThat(interpreter.getErrors()).isEmpty(); + } + private String val(String jinja) { return parse(jinja).render(interpreter).getValue(); }