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

Support big integers in truncatewords and slice filters #1617

Merged
merged 3 commits into from
Oct 11, 2022

Conversation

dylanahsmith
Copy link
Contributor

In a low-level implementation of liquid, I would like to treat conversion of filter arguments to slice, truncate and truncatewords with a saturating conversion to an i32 or u32. Having these work consistently also allows this conversion logic to be shared across these filters.

From a high-level perspective, the user would prefer if these were handled without an error for use cases like truncations and slicing. A saturating conversion seems like it would give the expected behaviour, considering that the arrays and strings themselves shouldn't be this large.

As such, I'm changing the reference implementation to adopt this behaviour.

raise if words + 1 < MAX_INT
# e.g. integer #{words} too big to convert to `int'
raise Liquid::ArgumentError, "integer #{words} too big for truncatewords"
# integer too big for Strin#split, but we can semantically assume no truncation is needed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Typo

@dylanahsmith dylanahsmith force-pushed the better-filter-overflow-handling branch from 047c920 to c0c191c Compare October 11, 2022 16:44
@dylanahsmith dylanahsmith merged commit c99c932 into master Oct 11, 2022
@dylanahsmith dylanahsmith deleted the better-filter-overflow-handling branch October 11, 2022 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants