-
Notifications
You must be signed in to change notification settings - Fork 284
Open
Description
Given this example:
import java.io.StringReader;
import java.io.StringWriter;
import org.testng.annotations.Test;
import com.github.mustachejava.DefaultMustacheFactory;
import com.github.mustachejava.Mustache;
import com.github.mustachejava.MustacheFactory;
public class SimpleMustacheTest
{
private static class MyObject
{
public String[] getNames()
{
return new String[] { "Fred", null };
}
}
@Test
public void simpleTest()
{
final String template = "{{#names}}{{.}}\n\n{{/names}}";
final MustacheFactory mustacheFactory = new DefaultMustacheFactory();
final Mustache mustache = mustacheFactory.compile(new StringReader(template), "test");
final StringWriter writer = new StringWriter();
mustache.execute(writer, new MyObject());
System.out.println(writer.toString());
}
}
Why do I get this?
Fred
SimpleMustacheTest$MyObject@4891a775
Effectively it looks like it's saying that if a value cannot be extracted for an element then I'll take the parent scope. If I'm doing a {{.}} then that parent scope seeking shouldn't happen should it? It's not like anyone would be saying that if I don't have a value then get my parent instead would they?
If this is a design decision then does that mean we have to wrap all objects in true/false checks?
Currently the scenario in the real code I'm forcing the data to always return empty string if the value is a null to overcome this issue.
Metadata
Metadata
Assignees
Labels
No labels