diff --git a/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java b/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java index 7f552755a..e7135f9f6 100644 --- a/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java +++ b/src/main/java/com/hubspot/jinjava/el/ExpressionResolver.java @@ -63,7 +63,7 @@ public ExpressionResolver(JinjavaInterpreter interpreter, ExpressionFactory expr */ public Object resolveExpression(String expression) { if (StringUtils.isBlank(expression)) { - return ""; + return null; } interpreter.getContext().addResolvedExpression(expression.trim()); @@ -121,7 +121,7 @@ else if (e.getCause() != null && e.getCause() instanceof InvalidArgumentExceptio String.format("Error resolving expression [%s]: " + getRootCauseMessage(e), expression), e, interpreter.getLineNumber(), interpreter.getPosition()))); } - return ""; + return null; } private void validateResult(Object result) { diff --git a/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java b/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java index 2ab442708..60a86eb1c 100644 --- a/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ExpressionResolverTest.java @@ -454,7 +454,7 @@ public void itBlocksDisabledFunctions() { final JinjavaConfig config = JinjavaConfig.newBuilder().withDisabled(disabled).build(); final RenderResult renderResult = jinjava.renderForResult(template, context, config); - assertEquals("hi ", renderResult.getOutput()); + assertEquals("hi ", renderResult.getOutput()); TemplateError e = renderResult.getErrors().get(0); assertThat(e.getItem()).isEqualTo(ErrorItem.FUNCTION); assertThat(e.getReason()).isEqualTo(ErrorReason.DISABLED); diff --git a/src/test/java/com/hubspot/jinjava/el/ExtendedSyntaxBuilderTest.java b/src/test/java/com/hubspot/jinjava/el/ExtendedSyntaxBuilderTest.java index 1689a7be5..adc95a2c0 100644 --- a/src/test/java/com/hubspot/jinjava/el/ExtendedSyntaxBuilderTest.java +++ b/src/test/java/com/hubspot/jinjava/el/ExtendedSyntaxBuilderTest.java @@ -274,8 +274,8 @@ public void arrayWithNegativeIndices() { assertThat(val("stringToSplit.split('-')")).isEqualTo(new String[]{ "one", "two", "three", "four", "five" }); assertThat(val("stringToSplit.split('-')[-1]")).isEqualTo("five"); - assertThat(val("stringToSplit.split('-')[1.5]")).isEqualTo(""); - assertThat(val("stringToSplit.split('-')[-1.5]")).isEqualTo(""); + assertThat(val("stringToSplit.split('-')[1.5]")).isEqualTo(null); + assertThat(val("stringToSplit.split('-')[-1.5]")).isEqualTo(null); // out of range returns null, as -6 + the length of the array is still // negative, and java doesn't support negative array indices. @@ -287,7 +287,7 @@ public void arrayWithNegativeIndices() { @Test public void invalidNestedAssignmentExpr() { - assertThat(val("content.template_path = 'Custom/Email/Responsive/testing.html'")).isEqualTo(""); + assertThat(val("content.template_path = 'Custom/Email/Responsive/testing.html'")).isEqualTo(null); assertThat(interpreter.getErrorsCopy()).isNotEmpty(); assertThat(interpreter.getErrorsCopy().get(0).getReason()).isEqualTo(ErrorReason.SYNTAX_ERROR); assertThat(interpreter.getErrorsCopy().get(0).getMessage()).containsIgnoringCase("identifier"); @@ -295,7 +295,7 @@ public void invalidNestedAssignmentExpr() { @Test public void invalidIdentifierAssignmentExpr() { - assertThat(val("content = 'Custom/Email/Responsive/testing.html'")).isEqualTo(""); + assertThat(val("content = 'Custom/Email/Responsive/testing.html'")).isEqualTo(null); assertThat(interpreter.getErrorsCopy()).isNotEmpty(); assertThat(interpreter.getErrorsCopy().get(0).getReason()).isEqualTo(ErrorReason.SYNTAX_ERROR); assertThat(interpreter.getErrorsCopy().get(0).getMessage()).containsIgnoringCase("'='"); @@ -303,7 +303,7 @@ public void invalidIdentifierAssignmentExpr() { @Test public void invalidPipeOperatorExpr() { - assertThat(val("topics|1")).isEqualTo(""); + assertThat(val("topics|1")).isEqualTo(null); assertThat(interpreter.getErrorsCopy()).isNotEmpty(); assertThat(interpreter.getErrorsCopy().get(0).getReason()).isEqualTo(ErrorReason.SYNTAX_ERROR); }