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

Add an optional limit argument to split filter #1801

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ahangarha
Copy link

This PR adds an optional limit argument to the split filter in Liquid to make it work similar to the Ruby split method.

Closes #1800

@ghost
Copy link

ghost commented May 31, 2024

Thanks for the PR! The typo in the PR title should be corrected to "Optional" I guess.

@gooroodev, can you review this too please?

@ahangarha ahangarha changed the title Add an ontional limit argument to split filter Add an optional limit argument to split filter Jun 1, 2024
def split(input, pattern)
input.to_s.split(pattern.to_s)
def split(input, pattern, limit = nil)
limit = limit.respond_to?(:to_i) ? limit.to_i : 0
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should use Liquid::Utils.to_integer here.

Copy link
Author

Choose a reason for hiding this comment

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

Oh! I didn't know. I will update the PR ASAP.

Copy link
Author

Choose a reason for hiding this comment

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

As per my research Liquid::Utils.to_integer might not be helpful since it doesn't return 0 if an empty string gets passed. Not sure if I am too sensitive here or the 'to_integer' method needs some update.

What do you suggest? @ianks

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.

Add limit to split filter, like split method in Ruby
2 participants