Skip to content

Commit

Permalink
Merge pull request #2742 from bolt/bugfix/handle-missing-files
Browse files Browse the repository at this point in the history
Throw 404 response when thumbnailing a missing image
  • Loading branch information
bobdenotter authored Aug 6, 2021
2 parents 108b1cd + 375c1ce commit c387131
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Controller/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,14 @@ private function buildImage(string $filename): string

private function buildResponse(string $filename): Response
{
$filepath = $this->getPath(null, false, $filename);

if (! (new Filesystem())->exists($filepath)) {
throw new NotFoundHttpException(sprintf("The file '%s' does not exist.", $filepath));
}

// In case we're trying to "thumbnail" an svg, just return the whole thing.
if ($this->isSvg($filename)) {
$filepath = sprintf('%s%s%s', $this->getPath(), DIRECTORY_SEPARATOR, $filename);

$response = new Response(file_get_contents($filepath));
$response->headers->set('Content-Type', 'image/svg+xml');

Expand Down

0 comments on commit c387131

Please sign in to comment.