Added defensive check for wpcom taxonomies endpoint#48070
Conversation
|
Are you an Automattician? Please test your changes on all WordPress.com environments to help mitigate accidental explosions.
Interested in more tips and information?
|
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Follow this PR Review Process:
If you have questions about anything, reach out in #jetpack-developers for guidance! Jetpack plugin: The Jetpack plugin has different release cadences depending on the platform:
If you have any questions about the release process, please ask in the #jetpack-releases channel on Slack. |
Code Coverage SummaryCoverage changed in 1 file.
|
josephscott
left a comment
There was a problem hiding this comment.
Looks good to me - we need more checks on return values in general.
tbradsha
left a comment
There was a problem hiding this comment.
This at least should address the reported issue. I'm not sure I agree with the "dead code" statement, but that'd require a lot more digging, so the current state is good enough.
At minimum, though, let's update the PR description to reflect what's actually changing. 🙂
Proposed changes
process_args()already returned aWP_Errorin that case, butcallback()passed the error straight intocategories()/tags(), which then treated it as an args array and threw errors whenget_categories()/get_tags()ran against aWP_Errorinstead of a real args array.is_wp_error()check incallback()so the error is returned to the client as a proper400 invalid_numberresponse instead of blowing up downstream.query_args()returning a non-array:WPCOM_JSON_API_Endpoint::query_args()builds its result viaarray_intersect_key()andcast_and_filter(), both of which always return an array for this endpoint's schema, so guarding against a non-array return would be dead code.Related product discussion/links
Does this pull request change what data or activity we track or use?
No.
Testing instructions
GET /sites/$site/categoriesendpoint, setnumberto a value greater than1000(e.g.1500), and run it against a site you have access to.number=5,number=100,number=1000(the boundary) should all return categories as expected.GET /sites/$site/tags.