Shopify / liquid

Liquid markup language. Safe, customer facing template language for flexible web apps.
https://shopify.github.io/liquid/
MIT License
11.13k stars 1.39k forks source link

Fix `BigDecimal` output in `sum` filter #1739

Closed adamklingbaum closed 1 year ago

adamklingbaum commented 1 year ago

Thank you, @jg-rp, for identifying this bug and helping to implement the fix.

Summary

This PR addresses a bug in the sum filter when handling arrays containing floats and thus yield a result that is a float.

Previously, the sum filter would return a BigDecimal, which would render in scientific notation, when summing floats. This behaviour was inconsistent with other math filters.

The change in this PR ensures that the sum filter returns a float instead of a BigDecimal when summing floats, aligning its behaviour with other math filters.

For example:

https://github.com/Shopify/liquid/blob/0b9318222bcc09681e52fd5b8e70262274e673bf/lib/liquid/standardfilters.rb#L908-L911

Changes