shortpixel-image-optimiser icon indicating copy to clipboard operation
shortpixel-image-optimiser copied to clipboard

Adjust <source> regex for CDN Controller

Open palicko opened this issue 9 months ago • 0 comments

Hey, we are using Shortpixel CDN delivery on bunch of our websites. Everything was working fine but we've noticed, that some urls were not replaced and tried to debug why. We've found that when <source> tag is written with srcset on new line, regex in CDNController.php doesn't match it.

To replicate it. This one is working:

<source srcset="https://website.com/myimage.jpg">

But this one is not:

<source 
    srcset="https://website.com/myimage.jpg"
    media="(max-width:760px)"
>

Regex for this is in CDNController::fetchImageMatches() and its this line:

$number = preg_match_all('/<img[^>]*>|<source srcset="[^>]*">/i', $content, $matches);

Changing regex to something like this is of course working:

$number = preg_match_all('/<img[^>]*>|<source\s+srcset="[^"]*"[^>]*>/i', $content, $matches);

Can you please look at that and maybe adjust that regex so it would work in this case as well? Many thanks.

palicko avatar Jul 30 '25 11:07 palicko