diff --git a/src/main/java/com/hubspot/jinjava/Jinjava.java b/src/main/java/com/hubspot/jinjava/Jinjava.java index 21179b86d..7079616bd 100644 --- a/src/main/java/com/hubspot/jinjava/Jinjava.java +++ b/src/main/java/com/hubspot/jinjava/Jinjava.java @@ -35,6 +35,7 @@ import com.hubspot.jinjava.lib.fn.ELFunctionDefinition; import com.hubspot.jinjava.lib.tag.Tag; import com.hubspot.jinjava.loader.ClasspathResourceLocator; +import com.hubspot.jinjava.loader.RelativePathResolver; import com.hubspot.jinjava.loader.ResourceLocator; import de.odysseus.el.ExpressionFactoryImpl; import de.odysseus.el.misc.TypeConverter; @@ -244,6 +245,10 @@ public RenderResult renderForResult( } else { context = new Context(copyGlobalContext(), bindings, renderConfig.getDisabled()); } + Object currentPath = context.get(RelativePathResolver.CURRENT_PATH_CONTEXT_KEY); + if (currentPath != null) { + context.getCurrentPathStack().pushWithoutCycleCheck(currentPath.toString(), 0, 0); + } JinjavaInterpreter interpreter = globalConfig .getInterpreterFactory() @@ -290,6 +295,9 @@ public RenderResult renderForResult( ); } finally { globalContext.reset(); + if (currentPath != null) { + context.getCurrentPathStack().pop(); + } JinjavaInterpreter.popCurrent(); } } diff --git a/src/test/java/com/hubspot/jinjava/EagerTest.java b/src/test/java/com/hubspot/jinjava/EagerTest.java index 142938e3e..7db5c58f9 100644 --- a/src/test/java/com/hubspot/jinjava/EagerTest.java +++ b/src/test/java/com/hubspot/jinjava/EagerTest.java @@ -625,7 +625,7 @@ public void itDefersMacroInIf() { @Test public void itPutsDeferredImportedMacroInOutput() { - expectedTemplateInterpreter.assertExpectedOutput( + expectedTemplateInterpreter.assertExpectedOutputNonIdempotent( "puts-deferred-imported-macro-in-output" ); } @@ -643,7 +643,7 @@ public void itPutsDeferredImportedMacroInOutputSecondPass() { @Test public void itPutsDeferredFromedMacroInOutput() { - expectedTemplateInterpreter.assertExpectedOutput( + expectedTemplateInterpreter.assertExpectedOutputNonIdempotent( "puts-deferred-fromed-macro-in-output" ); } diff --git a/src/test/resources/eager/puts-deferred-fromed-macro-in-output.expected.jinja b/src/test/resources/eager/puts-deferred-fromed-macro-in-output.expected.jinja index be059f126..fcf340374 100644 --- a/src/test/resources/eager/puts-deferred-fromed-macro-in-output.expected.jinja +++ b/src/test/resources/eager/puts-deferred-fromed-macro-in-output.expected.jinja @@ -1 +1 @@ -{% set myname = deferred + 3 %}{% set __macro_getPath_331491059_temp_variable_1__ %}Hello {{ myname }}{% endset %}{% print __macro_getPath_331491059_temp_variable_1__ %} +{% set myname = deferred + 3 %}{% set __macro_getPath_331491059_temp_variable_1__ %}{% set current_path = 'simple-with-call.jinja' %}Hello {{ myname }}{% set current_path = '' %}{% endset %}{% print __macro_getPath_331491059_temp_variable_1__ %} \ No newline at end of file diff --git a/src/test/resources/eager/puts-deferred-imported-macro-in-output.expected.jinja b/src/test/resources/eager/puts-deferred-imported-macro-in-output.expected.jinja index fde94f4f8..fcf340374 100644 --- a/src/test/resources/eager/puts-deferred-imported-macro-in-output.expected.jinja +++ b/src/test/resources/eager/puts-deferred-imported-macro-in-output.expected.jinja @@ -1 +1 @@ -{% set myname = deferred + 3 %}{% set __macro_getPath_331491059_temp_variable_1__ %}Hello {{ myname }}{% endset %}{% print __macro_getPath_331491059_temp_variable_1__ %} \ No newline at end of file +{% set myname = deferred + 3 %}{% set __macro_getPath_331491059_temp_variable_1__ %}{% set current_path = 'simple-with-call.jinja' %}Hello {{ myname }}{% set current_path = '' %}{% endset %}{% print __macro_getPath_331491059_temp_variable_1__ %} \ No newline at end of file