Commit f7470234 authored by Aaron Wells's avatar Aaron Wells
Browse files

Bug 1612451: Graceful handling of invalid embedded artefact id

Adds a try/catch block so that the code doesn't crash if
you've put in an invalid image ID in an embedded image tag.
Also tweaks the embed code so that it will skip invalid
images but continue processing the rest of the text block.

behatnotneeded: Covered by existing tests

Change-Id: I573adc7d29a0c1a4289f1b0a0b402d308a739be9
parent fa690464
......@@ -76,11 +76,18 @@ class EmbeddedImage {
$foundmatch = preg_match_all($searchpattern, $imgsrc, $matches);
if ($foundmatch) {
foreach ($matches[1] as $imgid) {
$file = artefact_instance_from_id($imgid);
if (!($file instanceof ArtefactTypeImage)
try {
$file = artefact_instance_from_id($imgid);
catch (ArtefactNotFoundException $e) {
if (
!($file instanceof ArtefactTypeImage)
|| !$user->can_publish_artefact($file)
) {
return $fieldvalue;
) {
else {
$publicimages[] = $imgid;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment