Skip to content

Commit 8c9a3c3

Browse files
committed
"empty" variable name does not work in a partial Fix #643
1 parent 8861cef commit 8c9a3c3

3 files changed

Lines changed: 23 additions & 4 deletions

File tree

handlebars/src/main/java/com/github/jknack/handlebars/internal/Partial.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ protected void merge(final Context context, final Writer writer)
195195

196196
}
197197
context.data(Context.CALLEE, this);
198-
Context ctx = Context.newPartialContext(context, this.scontext, hash(context));
198+
Map<String, Object> hash = hash(context);
199+
// HACK: hide/override local attribute with parent version (if any)
200+
hash.put("size", context.get("size"));
201+
hash.put("empty", context.get("empty"));
202+
Context ctx = Context.newPartialContext(context, this.scontext, hash);
199203
template.apply(ctx, writer);
200204
context.data(Context.CALLEE, callee);
201205
} catch (IOException ex) {

handlebars/src/test/java/com/github/jknack/handlebars/issues/Issue539.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
import com.github.jknack.handlebars.v4Test;
55
import org.junit.Test;
66

7-
import java.io.IOException;
8-
97
public class Issue539 extends v4Test {
108

119
@Override protected void configure(Handlebars handlebars) {
@@ -52,4 +50,4 @@ public void inlinePartialsLeak() throws Exception {
5250
+ "<br>\n"
5351
+ "<br>");
5452
}
55-
}
53+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.github.jknack.handlebars.issues;
2+
3+
import com.github.jknack.handlebars.v4Test;
4+
import org.junit.Test;
5+
6+
public class Issue643 extends v4Test {
7+
8+
@Test
9+
public void shouldAllowES6LetOrConstLiterals() throws Exception {
10+
shouldCompileTo("template: {{empty}} "
11+
+ "{{> partial}}",
12+
$("partials", $("partial", "partial: {{empty}}"),
13+
"data", $("empty", false)),
14+
"template: true partial: true");
15+
}
16+
17+
}

0 commit comments

Comments
 (0)