Validate repo_info before accessing version#92
Conversation
|
Fixed — moved the |
| $report['repo_info'] = $returned_object; | ||
| // Cache the report. | ||
| set_site_transient( $cache_key, $report, self::CACHE_LIFETIME ); | ||
| } |
There was a problem hiding this comment.
@Zodiac1978 Maybe we could add an else branch here to log the error? Your thoughts?
plugins_api() can return a valid object (not WP_Error) that lacks expected properties like `version`. This happens with plugins like Search & Filter Pro whose slug collides with a wp.org entry returning invalid data. Guard against this in two places: - assemble_plugin_report(): reject API responses missing `version` before caching as repo_info - render_table_row(): add isset() check on version, consistent with tested/rating/last_updated guards Fixes Zodiac1978#56
Move the isset(version) check inside the non-error branch so the else is only reached for WP_Error, letting PHPStan narrow the type correctly.
3045426 to
f5de638
Compare
|
@apermo I fixed the line endings and indentation issues I caused by the GitHub web editor in branch Could you cherry-pick commit |
|
@Zodiac1978 Cherry-picked While looking at the red CI, I confirmed all three failing checks are WordPress Coding Standards (3 errors)
Plugin Check (1 error + warnings)
I'm happy to fix the WPCS errors properly — either a small Want me to push the fix into this PR, or would you prefer a separate one? |
|
Let's do it in a separate one. Thank you so much for working on those issues! |
|
I will prepare the PR as Draft, with the plan to rebase once the rest is merged. |
|
The CI coding-standards fixes are now in #97 (draft, branched from |
|
Looks like I need to look up how I can rebase. Never done that before 😬 |
Will do that. I can also show you in Mannheim. |
Summary
plugins_api()responses missing theversionproperty before storing asrepo_info(prevents caching invalid data)isset( $report['repo_info']->version )guard in the version column ofrender_table_row()(protects against stale cache entries)This is consistent with how
tested,last_updated,num_ratings, andratingare already guarded withisset()on lines 536, 546, 554.Fixes #56
Context
plugins_api()can return a valid stdClass (not aWP_Error) that lacks expected properties. This happens when a premium plugin's slug collides with a wordpress.org entry that returns invalid data (e.g. Search & Filter Pro — see #56 comments). The object passes the! is_wp_error()check but accessing->versiontriggers PHP warnings.Test in WordPress Playground
Both Playground instances include a mu-plugin that strips the
versionproperty from Classic Editor'splugins_api()response, reproducing the Search & Filter Pro scenario from #56.Before (develop — shows the bug): Open in WordPress Playground
After (this branch — bug fixed): Open in WordPress Playground
Both instances include a mu-plugin that hooks
plugins_api_resultto strip theversionproperty from Classic Editor's API response, reproducing the Search & Filter Pro scenario. In the Before instance, this causes PHP warnings that corrupt the AJAX response — the Classic Editor row fails to load. In the After instance, the invalid response is handled gracefully.Pre-installed plugins:
Test plan