yireo / Yireo_NextGenImages

44 stars 26 forks source link

Function convertSuffix return unexpected result #22

Closed andrzej-spolnicki closed 6 months ago

andrzej-spolnicki commented 2 years ago

Hi,

In function convertSuffix is small bug. I believe intention was to replace suffix part (file extension) only. https://github.com/yireo/Yireo_NextGenImages/blob/efbb39c187292661d14ed2bbc1a04d5a22432bfb/Image/File.php#L123

Example: convertSuffix('/some/path/example.jpg.jpg', '.webp'); Expected :'/some/path/example.jpg.webp' Actual :'/some/path/example.webp.webp'

Proposed fast fix: return (string)preg_replace('/\.(jpg$|jpeg$|png$)/i', $destinationSuffix, $sourceFilename); Because $ matches the end of the string IMO this will be sufficient for now.

jissereitsma commented 2 years ago

Thanks! The regex can be made a bit more simple though with /\.(jpg|jpeg|png)$/i. I'm not merging anything right away, because I'm refactoring things as we speak to allow for a different folder for destination images. Plus, I would very much like to add tests for this as well. But thanks for your input - I didn't spot this myself!

jissereitsma commented 6 months ago

I'm closing this ticket due to inactivity.