make sure to generate valid filenames (#2238)

This commit is contained in:
Kevin Papst
2021-01-08 14:50:23 +01:00
committed by GitHub
parent a5fdf81df5
commit 244169d6d5
7 changed files with 80 additions and 14 deletions

View File

@@ -13,6 +13,7 @@ use App\Export\ExportContext;
use App\Export\ExportItemInterface;
use App\Repository\ProjectRepository;
use App\Repository\Query\TimesheetQuery;
use App\Utils\FileHelper;
use App\Utils\HtmlToPdfConverter;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
@@ -94,7 +95,7 @@ class PDFRenderer
public function render(array $timesheets, TimesheetQuery $query): Response
{
$context = new ExportContext();
$context->setOption('filename', 'kimai-export.pdf');
$context->setOption('filename', 'kimai-export');
$summary = $this->calculateSummary($timesheets);
$content = $this->twig->render($this->getTemplate(), array_merge([
@@ -116,10 +117,12 @@ class PDFRenderer
$filename = $context->getOption('filename');
if (empty($filename)) {
$filename = 'kimai-export.pdf';
$filename = 'kimai-export';
}
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename);
$filename = FileHelper::convertToAsciiFilename($filename);
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, $filename . '.pdf');
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', $disposition);