[jinja] disable failOnUnknownTokens (#16347)

Home Assistant doesn't enable strict mode, so we shouldn't either

Signed-off-by: Cody Cutrer <cody@cutrer.us>
Signed-off-by: Ciprian Pascu <contact@ciprianpascu.ro>
This commit is contained in:
Cody Cutrer 2024-02-04 03:57:54 -07:00 committed by Ciprian Pascu
parent 1e35a90c09
commit 2c5d803489
2 changed files with 5 additions and 9 deletions

View File

@ -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 <code>value</code> by Jinja template.

View File

@ -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