Skip to content

Commit

Permalink
Add test that tests bug seen in production, where the current_path after
Browse files Browse the repository at this point in the history
macro function executed with nested interpretation was not preserved.
With this change, by wrapping the output in a child scope, the
current_path is preserved
  • Loading branch information
jasmith-hs committed Sep 11, 2024
1 parent 9636a6e commit 84567ed
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/test/java/com/hubspot/jinjava/EagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1634,4 +1634,14 @@ public void prepareContext(Context context) {
"keeps-meta-context-variables-through-import/test"
);
}

@Test
public void itWrapsMacroThatWouldChangeCurrentPathInChildScope() {
interpreter
.getContext()
.put(RelativePathResolver.CURRENT_PATH_CONTEXT_KEY, "starting path");
expectedTemplateInterpreter.assertExpectedOutputNonIdempotent(
"wraps-macro-that-would-change-current-path-in-child-scope/test"
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% macro foo_importer() -%}
{%- include "../dir2/included.jinja" -%}
{%- print foo -%}
{%- endmacro %}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{% set foo = deferred %}
{{ foo }}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Starting current_path: starting path
Intermediate current_path: starting path
{% for __ignored__ in [0] %}\
{% set foo = deferred %}
{{ foo }}\
{% print foo %}\
{% endfor %}
Ending current_path: starting path
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Starting current_path: {{ current_path }}
{% from "./dir1/macro.jinja" import foo_importer -%}
Intermediate current_path: {{ current_path }}
{{ foo_importer() }}
Ending current_path: {{ current_path }}

0 comments on commit 84567ed

Please sign in to comment.