From 2c5d803489a7ce93e40a7d4cf8ccab3dd63b3330 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Sun, 4 Feb 2024 03:57:54 -0700 Subject: [PATCH] [jinja] disable failOnUnknownTokens (#16347) Home Assistant doesn't enable strict mode, so we shouldn't either Signed-off-by: Cody Cutrer Signed-off-by: Ciprian Pascu --- .../jinja/internal/JinjaTransformationService.java | 4 +--- .../jinja/internal/JinjaTransformationServiceTest.java | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/bundles/org.openhab.transform.jinja/src/main/java/org/openhab/transform/jinja/internal/JinjaTransformationService.java b/bundles/org.openhab.transform.jinja/src/main/java/org/openhab/transform/jinja/internal/JinjaTransformationService.java index e0e5df8094c..c7182c0a949 100644 --- a/bundles/org.openhab.transform.jinja/src/main/java/org/openhab/transform/jinja/internal/JinjaTransformationService.java +++ b/bundles/org.openhab.transform.jinja/src/main/java/org/openhab/transform/jinja/internal/JinjaTransformationService.java @@ -31,7 +31,6 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.hubspot.jinjava.Jinjava; -import com.hubspot.jinjava.JinjavaConfig; import com.hubspot.jinjava.interpret.FatalTemplateErrorsException; /** @@ -47,8 +46,7 @@ public class JinjaTransformationService implements TransformationService { private final Logger logger = LoggerFactory.getLogger(JinjaTransformationService.class); - private final JinjavaConfig config = JinjavaConfig.newBuilder().withFailOnUnknownTokens(true).build(); - private final Jinjava jinjava = new Jinjava(config); + private final Jinjava jinjava = new Jinjava(); /** * Transforms the input value by Jinja template. diff --git a/bundles/org.openhab.transform.jinja/src/test/java/org/openhab/transform/jinja/internal/JinjaTransformationServiceTest.java b/bundles/org.openhab.transform.jinja/src/test/java/org/openhab/transform/jinja/internal/JinjaTransformationServiceTest.java index ecf78c97168..c4211d48a74 100644 --- a/bundles/org.openhab.transform.jinja/src/test/java/org/openhab/transform/jinja/internal/JinjaTransformationServiceTest.java +++ b/bundles/org.openhab.transform.jinja/src/test/java/org/openhab/transform/jinja/internal/JinjaTransformationServiceTest.java @@ -76,15 +76,13 @@ public class JinjaTransformationServiceTest { } @Test - public void testMissingVariableError() { - assertThrows(TransformationException.class, - () -> processor.transform("Hello {{ missing }}!", "{\"string\": \"world\"}")); + public void testMissingVariableError() throws TransformationException { + assertEquals("Hello !", processor.transform("Hello {{ missing }}!", "{\"string\": \"world\"}")); } @Test - public void testMissingMapKeyError() { - assertThrows(TransformationException.class, - () -> processor.transform("Hello {{ value_json.missing }}!", "{\"string\": \"world\"}")); + public void testMissingMapKeyError() throws TransformationException { + assertEquals("Hello !", processor.transform("Hello {{ value_json.missing }}!", "{\"string\": \"world\"}")); } @Test