HubSpot / jinjava

Jinja template engine for Java
Apache License 2.0
690 stars 168 forks source link

Add more lenient coercing #1172

Open ruslanhubspot opened 5 months ago

ruslanhubspot commented 5 months ago

strings can be implicitly coerced to numeric values, so comparisons like:

{% if "1000" > 5%}

works. However evaluating:

{% if "1,000" > 5%}

or:

{% if "1000.25" > 5%}

throws an error. This adds some additional cleaning to allow formatted number strings to be parsed. Notably it does not remove decimals when comparing to floats, since those are valuable and:

{% if "1000.25" > 50.0 %}

already works.

It also only removes characters after decimals if its a properly formatted decimal number (so containing no non-digit characters and only one decimal point)

ruslanhubspot commented 5 months ago

discussion here: https://hubspot.slack.com/archives/CU7RT16A3/p1711737996514909?thread_ts=1711643951.818689&cid=CU7RT16A3