The `round` filter - Ruby 2.7 vs 3.1
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
There's a subtle difference in the round filter's behaviour when using Ruby 3.1, vs Ruby 2.7. Specifically, when the input value is a float (or anything that gets converted to a BigDecimal) and round is given an argument that gets coerced to 0, but is not 0, Ruby 2.7 will output a decimal point with a single zero, whereas Ruby 3.1 will not output a decimal point or trailing zero.
Template
{{ 1.0 | round }}
{{ 1.0 | round: 0 }}
{{ 1.0 | round: "0" }}
{{ 1.0 | round: "abc" }}
{{ 1.0 | round: nosuchthing }}
Output using Ruby 2.7.6
1
1
1.0
1.0
1.0
Output using Ruby 3.1.2
1
1
1
1
1
As far as I can tell, this is due to some fixes in Ruby's BigDecimal library.
The cases with the default argument and an explicit 0 are not affected because of the following line:
https://github.com/Shopify/liquid/blob/698130573651a7a0accc00a953057a9d424836c5/lib/liquid/standardfilters.rb#L772
I'm unsure how significant of a difference this is, but thought it was at least worth mentioning.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the listed Liquid template under Ruby 2.7.6 and 3.1.2, then inspect lib/liquid/standardfilters.rb around line 772 and the linked BigDecimal changes. Compare the round filter's behavior for each argument case; the issue does not specify a desired resolution.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100