Fix featured image rename failure on servers with .tmp in temp directory path#1256
Fix featured image rename failure on servers with .tmp in temp directory path#1256Copilot wants to merge 3 commits into
.tmp in temp directory path#1256Conversation
.tmp in temp directory path
There was a problem hiding this comment.
Pull request overview
Fixes a featured-image import failure caused by rewriting .tmp anywhere in the downloaded temp file path (including directory segments like /.tmp/) by only rewriting a trailing .tmp extension.
Changes:
- Replace the
.tmpextension rewrite fromstr_replace()to an end-anchoredpreg_replace('/\.tmp$/', ...)intry_save_featured_image(), preventing path corruption when temp directories include.tmp.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // so let's determine the file's mime type and then rename the .tmp file with that extension. | ||
| if ( in_array( $type, array_values( get_allowed_mime_types() ), true ) ) { | ||
| $new_local_file = str_replace( '.tmp', str_replace( 'image/', '.', $type ), $local_file ); | ||
| $new_local_file = preg_replace( '/\.tmp$/', str_replace( 'image/', '.', $type ), $local_file ); |
|
@Soare-Robert-Daniel, I'm not sure which solution would be the best one here. Could you please review Copilot's suggestion and confirm whether it looks correct? |
|
@claude[agent] evalue the current solution based on the original problem |
…vation Agent-Logs-Url: https://github.com/Codeinwp/feedzy-rss-feeds/sessions/c9e20d0d-b601-4ecc-84ef-267703743c41 Co-authored-by: Soare-Robert-Daniel <17597852+Soare-Robert-Daniel@users.noreply.github.com>
... The current solution correctly addresses the original problem. The fix has two parts:
The See commit 361f006. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
Plugin build for 361f006 is ready 🛎️!
Note You can preview the changes in the Playground |
try_save_featured_image()usedstr_replace('.tmp', ...)to swap the downloaded file's.tmpextension for the real MIME extension. On servers where the system temp directory itself contains.tmpin its path (e.g./usr/home/user/.tmp/), this corrupts the directory segment too — producing a path like/usr/home/user/.jpeg/file.jpeg— causingrename()to fail for every import.Change
includes/admin/feedzy-rss-feeds-import.php— replacestr_replacewith an end-anchoredpreg_replaceso only the.tmpfile extension is rewritten, and usewp_get_default_extension_for_mime_type()for safer extension derivation that handles all MIME types (not justimage/*):Using
wp_get_default_extension_for_mime_type()ensures non-image MIME types (e.g.application/pdf) also get a valid file extension, matching the same pattern already used earlier in this method.