From 518995d1559b1db21b24fdd574c345fb9cfe16ed Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Tue, 3 Aug 2021 10:13:01 +0000 Subject: [PATCH] [CONTROLLER][Attachment] Assert that the supplied is positive and add documentation --- src/Controller/Attachment.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Controller/Attachment.php b/src/Controller/Attachment.php index 9d4c07830d..b7343b19e6 100644 --- a/src/Controller/Attachment.php +++ b/src/Controller/Attachment.php @@ -39,12 +39,20 @@ use Symfony\Component\Mime\MimeTypes; class Attachment extends Controller { + /** + * Generic function that handles getting a representation for an attachment + */ private function attachment(int $id, callable $handle) { - if (Event::handle('AttachmentFileInfo', [$id, &$res]) != Event::stop) { - // If no one else claims this attachment, use the default representation - $res = GSFile::getAttachmentFileInfo($id); + if ($id <= 0) { + throw new ClientException(_m('No such attachment'), 404); + } else { + if (Event::handle('AttachmentFileInfo', [$id, &$res]) != Event::stop) { + // If no one else claims this attachment, use the default representation + $res = GSFile::getAttachmentFileInfo($id); + } } + if (!empty($res)) { return $handle($res); } else {