Skip to content

Mustache mistakes "0" value for false #24

@S2MBO

Description

@S2MBO

Applies to feature/refactor.

Say you have the following in your metaJSON

{
                "name" : "type",
                "base-type" : "number",
                "description" : "the type of product",
                "required" : 1, 
                "minValue" : 0,
                "maxValue" : 1
}

and you want to perform some validation, for example in Java:

        {{#minValue}}
        if (newValue < {{minValue}}) {
            throw new InvalidArgumentException("Number " + newValue + " is smaller than {{minValue}}.");
        }
        {{/minValue}}

the code block is never generated. In fact mustache, due to its JavaScript nature, seems to evals an integer "0" to a boolean "false".

A possible work-around for this could be havinge pre-defined mustache keys has[Min,Max][Length,Value,Key].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions