-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR! The typo in the PR title should be corrected to "Optional" I guess. @gooroodev, can you review this too please? |
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 |
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.
I think we should use Liquid::Utils.to_integer
here.
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.
Oh! I didn't know. I will update the PR ASAP.
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.
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
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.
Sorry I meant Liquid::Utils.to_number
This PR adds an optional limit argument to the
split
filter in Liquid to make it work similar to the Rubysplit
method.Closes #1800