Skip to content

Coercing Strings to Integers Inside Filters #49

@jg-rp

Description

@jg-rp

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    incompatibilityBehavioural differences between Python and Ruby LiquidwontfixThis will not be worked on

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions