samskivert / jmustache

A Java implementation of the Mustache templating language.
Other
834 stars 128 forks source link

emptyStringIsFalse flag now works with any Object. #107

Closed greg-simon closed 5 years ago

greg-simon commented 5 years ago

Previously, only String types were checked for being empty. Now the Formatter is used to format the Object before checking for being empty.

Example of before change behaviour:

Mustache.Compiler compiler = Mustache.compiler().emptyStringIsFalse(true);
compiler.isFalsey(""); // true

Object myEmptyStrObj = new Object(){
    @Override
    public String toString() {
        return "";
    }
};
compiler.isFalsey(myEmptyStrObj); // false

After this change both isFalsey calls will return true;