Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dpep
Copy link

@dpep dpep commented Nov 22, 2024

I stumbled upon a corner case where Kaminari explodes with a divided by 0 error and wanted to offer a fix. The usage is a little contrived / self inflicted, but kaminari should probably be more resilient to user silliness.

Repro:

Kaminari::PaginatableArray.new([]).page(n).per(0).per(3)
# kaminari-core/lib/kaminari/models/page_scope_methods.rb:17:in `/': divided by 0 (ZeroDivisionError)

# or

Model.page(n).per(0).per(3)
# kaminari-core/lib/kaminari/models/page_scope_methods.rb:17:in `/': divided by 0 (ZeroDivisionError)

the issue arises because in .per, this library uses limit_value to recalculate the new offset value. but if limit_value is 0, it explodes. It's unclear what the offset should be set to (since we don't store page number, only offset), but resetting to 0 seemed sane.

Open to a bugfix?

@dpep
Copy link
Author

dpep commented Jan 16, 2025

@amatsuda mind taking a look?

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.

1 participant