Angrycreative / bj-lazy-load

WordPress plugin for lazy loading
GNU General Public License v2.0
40 stars 25 forks source link

Fix matching of HTML attributes in filter_images() #54

Open jan-san opened 5 years ago

jan-san commented 5 years ago

The code used to replace srcset and sizes attributes is overly simple and can cause issues like replacing parts of the src or other unrelated attributes:

// also replace the srcset (responsive images)
$replaceHTML = str_replace( 'srcset', 'data-lazy-srcset', $replaceHTML );
// replace sizes to avoid w3c errors for missing srcset
$replaceHTML = str_replace( 'sizes', 'data-lazy-sizes', $replaceHTML );

To fix this, we need to implement a proper parsing of the HTML tag and its attributes.

The issue was reported on wordpress.org: https://wordpress.org/support/topic/broken-image-10/

jan-san commented 5 years ago

This issue will become obsolete with #58.