Lazy Loading Image breaks if src contains single quote
-
Hi. I’ve got some shortcodes on my site that are meant to be put in the src attribute of an image. The shortcodes themselves contain attributes surrounded by single quotes (src is surrounded by double quotes).
<img src="[my_shortcode id='1' height='200']">
When lazy loading is enabled in Speed Optimizer, the src ends up getting cut off when the first single quote is encountered, breaking the shortcode and the image.
<img decoding="async" class="alignleft lazyloaded" src="[my_shortcode id=" data-src="[my_shortcode" id=" 1' height="160" ]" border="0">
I traced the issue back to the regular expressions in the Lazy_Load_Images class. Looks like they will start with either a single or double quote after the src attribute, and stop after either a single or double quote as well. I believe you can use backreferences in the regular expressions to stop at the same character you start at, for example:
(?<!noscript\>)((<img.*?src=(["|\']).*?\3).*?(\/?>))
- The topic ‘Lazy Loading Image breaks if src contains single quote’ is closed to new replies.