Regular expression matching on image needs adjustment
-
If there is a space in the filename of the image, it is matched, but the replacement for the data-lazy-src attribute is not handled correctly.
The problem seems to be in lazy-load.php on this line:
$content = preg_replace( '#<img([^>]+?)src=[\'"]?([^\'"\s>]+)[\'"]?([^>]*)>#', sprintf( '<img${1}src="%s" data-lazy-src="${2}"${3}><noscript><img${1}src="${2}"${3}></noscript>', $placeholder_image ), $content );
Example:
<img style=”float: left;” src=”https://mysite.com/wp-content/uploads/2013/october/Deer vs eagle.jpg” alt=”Deer vs Eagle” />
Gets replaced with:
<img style=”float: left;” src=”https://mysite.com/wp-content/plugins/lazy-load/images/1×1.trans.gif” data-lazy-src=”https://mysite.com/wp-content/uploads/2013/october/Deer” vs eagle.jpg” alt=”Deer vs Eagle” />
As you can see the filename is split and an extra quote is inserted.
Perhaps the capture group needs a slight change?
- The topic ‘Regular expression matching on image needs adjustment’ is closed to new replies.