Media: guard attachment icon size lookup#11613
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
e220135 to
3496f8b
Compare
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| $filter = static function () { | ||
| return 'https://example.org/wp-includes/images/media/missing-icon.png'; | ||
| }; | ||
|
|
||
| add_filter( 'wp_mime_type_icon', $filter ); |
There was a problem hiding this comment.
| $filter = static function () { | |
| return 'https://example.org/wp-includes/images/media/missing-icon.png'; | |
| }; | |
| add_filter( 'wp_mime_type_icon', $filter ); | |
| add_filter( | |
| 'wp_mime_type_icon', | |
| static function () { | |
| return 'https://example.org/wp-includes/images/media/missing-icon.png'; | |
| } | |
| ); |
|
|
||
| remove_filter( 'wp_mime_type_icon', $filter ); |
There was a problem hiding this comment.
No need to remove filters manually. This is done automatically when a test runs.
| remove_filter( 'wp_mime_type_icon', $filter ); |
| /** | ||
| * @ticket 64742 | ||
| */ | ||
| public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read() { |
There was a problem hiding this comment.
| public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read() { | |
| public function test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read(): void { |
This PR is only including a test, right? The PR description makes it sounds like it is attempting to fix something. If so, please make it clear this is a follow-up to r62176. |
|
@dhrupo thanks for this PR. Would you have some time over the next days to take a look at this? We'd potentially want to include this in WP 7.0.1 and would need the feedback fixed to continue. Else feel free to let us know. |
|
@masteradhoc thanks for the nudge — done, the review feedback is now addressed:
Both tests pass locally: Should be good to include in 7.0.1. Let me know if you'd like anything else adjusted. |
Apply review suggestions: add void return type, inline the filter closure, and drop the manual remove_filter() teardown.
c6a6970 to
47ce51e
Compare
Summary
Add a regression test for the icon fallback path in
wp_get_attachment_image_src()whenwp_getimagesize()cannot read the icon file.This is a test-only follow-up to [r62176], which fixed the underlying issue. That changeset guarded the icon fallback so that when
wp_getimagesize()returns a falsey value (the icon file cannot be read), width and height are only read when an array is returned — preserving the existingfalsereturn behavior instead of surfacing an incorrect array access on PHP 8.5.This PR does not change any source; it adds coverage to lock in that behavior.
Trac ticket: https://core.trac.wordpress.org/ticket/64742
Testing
Added a PHPUnit regression test that forces the mime type icon path to point at a missing icon file and verifies
wp_get_attachment_image_src()returnsfalsecleanly.Verified in the configured local
wordpress-developenvironment with:node ./tools/local-env/scripts/docker.js exec --user wp_php php ./vendor/bin/phpunit --filter test_wp_get_attachment_image_src_with_icon_when_icon_file_size_cannot_be_read tests/phpunit/tests/media.phpnode ./tools/local-env/scripts/docker.js exec --user wp_php php ./vendor/bin/phpunit --filter 'test_wp_get_attachment_image_(url|src_with_icon_when_icon_file_size_cannot_be_read)' tests/phpunit/tests/media.php