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

Last should accept 0 as limit #6419

Closed
BaibhaVatsa opened this issue Oct 11, 2019 · 1 comment · Fixed by #6420
Labels
Milestone

Comments

@BaibhaVatsa
Copy link
Contributor

@BaibhaVatsa BaibhaVatsa commented Oct 11, 2019

Issue description

Currently, Last throws an error if 0 is passed as a limit even though that usage should not crash things.
Further, first accepts 0 as a value for limit and returns an empty slice in that case so for consistency last should also accept 0 as limit.

What version of Hugo are you using (hugo version)?

$ hugo version
Hugo Static Site Generator v0.59.0-DEV-096A4B67 linux/amd64 BuildDate: 2019-10-11T02:36:33-0500

Does this issue reproduce with the latest release?

Yes

@bep bep added this to the v0.59 milestone Oct 11, 2019
@bep bep added the Enhancement label Oct 11, 2019
@bep

This comment has been minimized.

Copy link
Member

@bep bep commented Oct 11, 2019

I agree. I labeled this as an Enhancement, as I guess there are test cases for it. But you are right, what you say makes much more sense.

BaibhaVatsa added a commit to BaibhaVatsa/hugo that referenced this issue Oct 11, 2019
Modified the if conditional because of which last threw an error if 0 was passed as limit. The function now returns an empty slice if it is called with 0 as limit. The behavior of first and last is now the same when 0 is passed as limit. Also added tests to test the new behavior.

Fixes gohugoio#6419
@bep bep closed this in #6420 Oct 11, 2019
bep added a commit that referenced this issue Oct 11, 2019
Modified the if conditional because of which last threw an error if 0 was passed as limit. The function now returns an empty slice if it is called with 0 as limit. The behavior of first and last is now the same when 0 is passed as limit. Also added tests to test the new behavior.

Fixes #6419
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.