Skip to content

Commit

Permalink
Sync up current_path with CurrentPathStack when starting render
Browse files Browse the repository at this point in the history
  • Loading branch information
jasmith-hs committed Sep 6, 2024
1 parent 74d9a4d commit de36db9
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/main/java/com/hubspot/jinjava/Jinjava.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -290,6 +295,9 @@ public RenderResult renderForResult(
);
} finally {
globalContext.reset();
if (currentPath != null) {
context.getCurrentPathStack().pop();
}
JinjavaInterpreter.popCurrent();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/hubspot/jinjava/EagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ public void itDefersMacroInIf() {

@Test
public void itPutsDeferredImportedMacroInOutput() {
expectedTemplateInterpreter.assertExpectedOutput(
expectedTemplateInterpreter.assertExpectedOutputNonIdempotent(
"puts-deferred-imported-macro-in-output"
);
}
Expand All @@ -643,7 +643,7 @@ public void itPutsDeferredImportedMacroInOutputSecondPass() {

@Test
public void itPutsDeferredFromedMacroInOutput() {
expectedTemplateInterpreter.assertExpectedOutput(
expectedTemplateInterpreter.assertExpectedOutputNonIdempotent(
"puts-deferred-fromed-macro-in-output"
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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__ %}
Original file line number Diff line number Diff line change
@@ -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__ %}

0 comments on commit de36db9

Please sign in to comment.