Fix infinite recursion.

This commit is contained in:
serkan
2012-04-06 16:33:21 +02:00
parent 7701880092
commit 4d9a664214
@@ -523,6 +523,10 @@ public class Mustache
protected static class IncludedTemplateSegment extends Template.Segment { protected static class IncludedTemplateSegment extends Template.Segment {
public IncludedTemplateSegment (final String templateName, final Compiler compiler) { public IncludedTemplateSegment (final String templateName, final Compiler compiler) {
this.compiler = compiler;
this.templateName = templateName;
}
@Override public void execute (Template tmpl, Template.Context ctx, Writer out) {
Reader r; Reader r;
try { try {
r = compiler.loader.getTemplate(templateName); r = compiler.loader.getTemplate(templateName);
@@ -533,14 +537,13 @@ public class Mustache
throw new MustacheException("Unable to load template: " + templateName, e); throw new MustacheException("Unable to load template: " + templateName, e);
} }
} }
_template = compiler.compile(r); Template _template = compiler.compile(r);
}
@Override public void execute (Template tmpl, Template.Context ctx, Writer out) {
// we must take care to preserve our context rather than creating a new one, which // we must take care to preserve our context rather than creating a new one, which
// would happen if we just called execute() with ctx.data // would happen if we just called execute() with ctx.data
_template.executeSegs(ctx, out); _template.executeSegs(ctx, out);
} }
protected final Template _template; protected String templateName;
protected Compiler compiler;
} }
/** A helper class for named segments. */ /** A helper class for named segments. */