Fix lazyimg single quotes (#4330)

Little bug for cases with single quote in URL such as

```html
<img src="123?format='jpg'" />
```

Could probably be replaced by `loading="lazy"` in the future, and with a better DOM-aware method, for instance during SimplePie `add_attributes()`
pull/4329/head
Alexandre Alapetite 2 years ago committed by GitHub
parent 046598e743
commit 0b86e347ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      lib/lib_rss.php

@ -458,11 +458,16 @@ function validateEmailAddress($email) {
* Add support of image lazy loading
* Move content from src attribute to data-original
* @param string $content is the text we want to parse
* @return string
*/
function lazyimg($content) {
return preg_replace(
'/<((?:img|iframe)[^>]+?)src=[\'"]([^"\']+)[\'"]([^>]*)>/i',
return preg_replace([
'/<((?:img|iframe)[^>]+?)src="([^"]+)"([^>]*)>/i',
"/<((?:img|iframe)[^>]+?)src='([^']+)'([^>]*)>/i",
], [
'<$1src="' . Minz_Url::display('/themes/icons/grey.gif') . '" data-original="$2"$3>',
"<$1src='" . Minz_Url::display('/themes/icons/grey.gif') . "' data-original='$2'$3>",
],
$content
);
}

Loading…
Cancel
Save