Skip to content
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

Coercing Strings to Integers Inside Filters #49

Open
jg-rp opened this issue Mar 15, 2022 · 0 comments
Open

Coercing Strings to Integers Inside Filters #49

jg-rp opened this issue Mar 15, 2022 · 0 comments
Labels
incompatibility Behavioural differences between Python and Ruby Liquid wontfix This will not be worked on

Comments

@jg-rp
Copy link
Owner

jg-rp commented Mar 15, 2022

Many filters built in to Liquid will automatically convert a string representation of a number to an integer or float as needed.

When converting integers, Ruby Liquid uses Ruby's String.to_i method, which will disregard trailing non-digit characters. In the following example, '7,42' is converted to 7

template:

{{ 3.14 | plus: '7,42' }}
{{ '123abcdef45' | plus: '1,,,,..!@qwerty' }}

output

10.14
124

Python Liquid currently falls back to 0 for any string that can't be converted to an integer in its entirety. As is the case in Ruby Liquid for strings without leading digits.

This does not apply to parsing of integer literals, only converting strings to integers (not floats) inside filters.

@jg-rp jg-rp added the incompatibility Behavioural differences between Python and Ruby Liquid label Mar 15, 2022
@jg-rp jg-rp added the wontfix This will not be worked on label Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
incompatibility Behavioural differences between Python and Ruby Liquid wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

1 participant