Skip to content

conditional helpers throw ClassCastExceptions when arguments are different classes #827

@dontgitit

Description

@dontgitit

For instance, something like {{gt 5 2.0}} will throw:

[info]   com.github.jknack.handlebars.HandlebarsException: inline@690f730c:1:3: java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer
[info]     inline@690f730c:1:3
[info]   at java.lang.Integer.compareTo(Integer.java:52)
[info]   at com.github.jknack.handlebars.helper.ConditionalHelpers.cmp(ConditionalHelpers.java:399)
[info]   at com.github.jknack.handlebars.helper.ConditionalHelpers$3.apply(ConditionalHelpers.java:131)

However, when both arguments are the same class, it works as expected; both {{gt 5 2}} and {{gt 5.0 2.0}} produce true

It seems like for numeric conditionals like lt/gt, need to do some numeric conversion maybe via Number/BigDecimal/Double or something? Not sure what handlebars.js does for mixed types...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions