Skip to content

Commit 84567ed

Browse files
committed
Add test that tests bug seen in production, where the current_path after
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
1 parent 9636a6e commit 84567ed

5 files changed

Lines changed: 29 additions & 0 deletions

File tree

src/test/java/com/hubspot/jinjava/EagerTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1634,4 +1634,14 @@ public void prepareContext(Context context) {
16341634
"keeps-meta-context-variables-through-import/test"
16351635
);
16361636
}
1637+
1638+
@Test
1639+
public void itWrapsMacroThatWouldChangeCurrentPathInChildScope() {
1640+
interpreter
1641+
.getContext()
1642+
.put(RelativePathResolver.CURRENT_PATH_CONTEXT_KEY, "starting path");
1643+
expectedTemplateInterpreter.assertExpectedOutputNonIdempotent(
1644+
"wraps-macro-that-would-change-current-path-in-child-scope/test"
1645+
);
1646+
}
16371647
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{% macro foo_importer() -%}
2+
{%- include "../dir2/included.jinja" -%}
3+
{%- print foo -%}
4+
{%- endmacro %}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{% set foo = deferred %}
2+
{{ foo }}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Starting current_path: starting path
2+
Intermediate current_path: starting path
3+
{% for __ignored__ in [0] %}\
4+
{% set foo = deferred %}
5+
{{ foo }}\
6+
{% print foo %}\
7+
{% endfor %}
8+
Ending current_path: starting path
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Starting current_path: {{ current_path }}
2+
{% from "./dir1/macro.jinja" import foo_importer -%}
3+
Intermediate current_path: {{ current_path }}
4+
{{ foo_importer() }}
5+
Ending current_path: {{ current_path }}

0 commit comments

Comments
 (0)