-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix: prevent division by zero when pageSize is 0 or negative #8271
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,6 +50,11 @@ export default { | |
| allSelected = true | ||
| } | ||
|
|
||
| if (opts.pageSize <= 0) { | ||
| opts.pageSize = opts.totalRows | ||
| allSelected = true | ||
| } | ||
|
Comment on lines
+53
to
+56
|
||
|
|
||
| this.totalPages = ~~((opts.totalRows - 1) / opts.pageSize) + 1 | ||
|
|
||
| opts.totalPages = this.totalPages | ||
|
|
||
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.
The
pageSize <= 0normalization is insideif (opts.totalRows), butpageFrom/pageToare calculated later unconditionally usingopts.pageSize. IftotalRowsis 0 (or otherwise falsy) andpageSizeis 0/negative, this leaves an invalid page range (e.g.pageFrombecomes 1 whilepageTocan be 0/negative), which can leak into pagination info rendering (notably whenonlyInfoPaginationis enabled, the pagination container isn't auto-hidden for empty data). Consider normalizingopts.pageSize(or using a local effective page size) before theopts.totalRowscheck, and ensure arithmetic uses a positive page size even whentotalRowsis 0.