Follow-up: enforce positive whole page values in Collection pagination#838
Follow-up: enforce positive whole page values in Collection pagination#838chadwickmeyer wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 743bf17bf4
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const validPage = this.normalizePositiveWholeNumber(page) | ||
| this.paginate = !isUndefined(validPage) | ||
| if (isUndefined(validPage)) { | ||
| delete this.meta.get('api').p |
There was a problem hiding this comment.
Guard api metadata before deleting page on invalid input
In page(), the invalid-input branch calls delete this.meta.get('api').p before any code ensures meta.api exists. For a fresh Collection where no api metadata has been set yet, this.meta.get('api') is undefined, so this throws at runtime instead of safely ignoring the bad page value; this means malformed page params can now crash pagination flow rather than being handled defensively.
Useful? React with 👍 / 👎.
Motivation
-1,1.5,Infinity,NaN) being forwarded to the API viaapi.pand causing incorrect pagination.Description
normalizePositiveWholeNumber()that returns a finite integer>= 1orundefinedfor invalid inputs.sync()added defensive handling fordata.psopis normalized and removed when invalid before serializing the request.page(page)to validate the incomingpagevalue, short-circuit on invalid input, and only setmeta.api.pwhen the value is a valid whole positive number.Testing
git diff --checkto validate there are no whitespace/patch issues and it passed.git diffto verify the intended edits topackages/angularjs/src/services/collection.tswere applied as expected.Codex Task