Skip to content

Commit

Permalink
format: Viewable Images Bug
Browse files Browse the repository at this point in the history
This addresses a small bug where `Format::viewableImages()` was using
unencoded quotes instead of encoded quotes to replace the `<img src=`
matches. This means when the content is added to a textarea’s
`draft-data-original` attribute the unencoded quotes break the attribute
and displays raw HTML content. This moves the `Format::htmlchars()` call
after the `preg_replace_callback()` so the quotes can be properly
encoded (if needed).
  • Loading branch information
JediKev committed Oct 25, 2023
1 parent 4919051 commit 2a41288
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions include/class.format.php
Original file line number Diff line number Diff line change
Expand Up @@ -588,16 +588,15 @@ static function viewableImages($html, $options=array(), $format=false) {
$cids = $images = array();
$options +=array(
'disposition' => 'inline');
if ($format)
$html = Format::htmlchars($html, true);
return preg_replace_callback('/("|&quot;)cid:([\w._-]{32})("|&quot;)/',
$html = preg_replace_callback('/("|&quot;)cid:([\w._-]{32})("|&quot;)/',
function($match) use ($options, $images) {
if (!($file = AttachmentFile::lookup($match[2])))
return $match[0];

return sprintf('"%s" data-cid="%s"',
$file->getDownloadUrl($options), $match[2]);
}, $html);
return $format ? Format::htmlchars($html, true) : $html;
}


Expand Down

0 comments on commit 2a41288

Please sign in to comment.