File tree Expand file tree Collapse file tree 2 files changed +24
-20
lines changed
main/java/com/hubspot/jinjava/lib/expression
test/java/com/hubspot/jinjava/tree Expand file tree Collapse file tree 2 files changed +24
-20
lines changed Original file line number Diff line number Diff line change @@ -22,6 +22,16 @@ public RenderedOutputNode interpretOutput(
2222 master .getExpr (),
2323 master .getLineNumber ()
2424 );
25+
26+ final FeatureActivationStrategy feat = interpreter
27+ .getConfig ()
28+ .getFeatures ()
29+ .getActivationStrategy (ECHO_UNDEFINED );
30+
31+ if (var == null && feat .isActive (interpreter .getContext ())) {
32+ return new RenderedOutputNode (master .getImage ());
33+ }
34+
2535 String result = interpreter .getAsString (var );
2636
2737 if (interpreter .getConfig ().isNestedInterpretationEnabled ()) {
@@ -43,14 +53,6 @@ public RenderedOutputNode interpretOutput(
4353 if (interpreter .getContext ().isAutoEscape () && !(var instanceof SafeString )) {
4454 result = EscapeFilter .escapeHtmlEntities (result );
4555 }
46- final FeatureActivationStrategy feat = interpreter
47- .getConfig ()
48- .getFeatures ()
49- .getActivationStrategy (ECHO_UNDEFINED );
50-
51- if (result .isEmpty () && feat .isActive (interpreter .getContext ())){
52- result = master .getImage ();
53- }
5456
5557 return new RenderedOutputNode (result );
5658 }
Original file line number Diff line number Diff line change @@ -133,24 +133,26 @@ public void itRendersStringRange() throws Exception {
133133 }
134134
135135 @ Test
136- public void itRenderDebugUndefined () {
137-
136+ public void itRenderEchoUndefined () {
138137 final JinjavaConfig config = JinjavaConfig
139- .newBuilder ()
140- .withFeatureConfig (FeatureConfig
141- .newBuilder ()
142- . add ( ECHO_UNDEFINED , FeatureStrategies . ACTIVE ). build () )
143- .build ();
138+ .newBuilder ()
139+ .withFeatureConfig (
140+ FeatureConfig .newBuilder (). add ( ECHO_UNDEFINED , FeatureStrategies . ACTIVE ). build ()
141+ )
142+ .build ();
144143 final JinjavaInterpreter jinjavaInterpreter = new Jinjava (config ).newInterpreter ();
145144 jinjavaInterpreter .getContext ().put ("subject" , "this" );
146145
147- String template = "{{ subject | capitalize() }} expression {{ testing.template('hello_world') }} " +
148- "has a {{ unknown | lower() }} " +
149- "token but {{ unknown | default(\" replaced\" ) }}" ;
146+ String template =
147+ "{{ subject | capitalize() }} expression {{ testing.template('hello_world') }} " +
148+ "has a {{ unknown | lower() }} " +
149+ "token but {{ unknown | default(\" replaced\" ) }} and empty {{ '' }}" ;
150150 Node node = new TreeParser (jinjavaInterpreter , template ).buildTree ();
151151 assertThat (jinjavaInterpreter .render (node ))
152- .isEqualTo ("This expression {{ testing.template('hello_world') }} " +
153- "has a {{ unknown | lower() }} token but replaced" );
152+ .isEqualTo (
153+ "This expression {{ testing.template('hello_world') }} " +
154+ "has a {{ unknown | lower() }} token but replaced and empty "
155+ );
154156 }
155157
156158 @ Test
You can’t perform that action at this time.
0 commit comments