New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update item_property to recognize integers #7878
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of recommendations:
- The two regexes would best be defined as a pair of
private_constant
instead. - Prefer stashing the stringified property in a local variable instead of opening chances for multiple stringifications (e.g. when the first branch is going to evaluate to a
false
) - Prefer using
String#match?
overString#=~
when the logic doesn't involve reading the matchdata.
Two quick questions:
|
Windows failures are only on GH Actions: There's a PR to patch that: #7885 |
Liquid has a utility function: def self.to_number(obj)
case obj
when Float
BigDecimal(obj.to_s)
when Numeric
obj
when String
/\A-?\d+\.\d+\z/.match?(obj.strip) ? BigDecimal(obj) : obj.to_i
else
if obj.respond_to?(:to_number)
obj.to_number
else
0
end
end
end |
Actually it is not required to cast to string or to any type at all, since data comes in typed manner from yaml files. But |
@summerisgone The reason |
@ashmaroli what is your suggestion, to import |
@summerisgone Its a public method. So you can call it directly. For example: Liquid::Utils.to_number(input) However, you may need to add additional tests to ensure expected results for various objects. |
@ashmaroli I tried to use |
@ashmaroli what else blocks the merge? |
@summerisgone The change looks okay. |
@jekyllbot: merge +minor |
Update item_property to recognize integers This backports eb81dc0 to 4.0-stable
This is a 🐛 bug fix
I've added tests
no need to update documentation
The test suite passes locally
Summary
Method
item_property
aggressively parses floats from values. In order to properly render integers I added integer check before float check. I guess better solution would be type check, but I'm afraid it might break other things.Context
Fixes #7827
--
P.S.
Thanks for wonderful software, glad to bring my 5 cents!