Skip to content

Commit 2a41288

Browse files
committed
format: Viewable Images Bug
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).
1 parent 4919051 commit 2a41288

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

include/class.format.php

+2-3
Original file line numberDiff line numberDiff line change
@@ -588,16 +588,15 @@ static function viewableImages($html, $options=array(), $format=false) {
588588
$cids = $images = array();
589589
$options +=array(
590590
'disposition' => 'inline');
591-
if ($format)
592-
$html = Format::htmlchars($html, true);
593-
return preg_replace_callback('/("|&quot;)cid:([\w._-]{32})("|&quot;)/',
591+
$html = preg_replace_callback('/("|&quot;)cid:([\w._-]{32})("|&quot;)/',
594592
function($match) use ($options, $images) {
595593
if (!($file = AttachmentFile::lookup($match[2])))
596594
return $match[0];
597595

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

603602

0 commit comments

Comments
 (0)