Skip to content

Commit

Permalink
sanitized file names for download
Browse files Browse the repository at this point in the history
  • Loading branch information
danigargar committed Apr 3, 2024
1 parent 901f8e7 commit b754427
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Symfony/Controller/DownloadAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,20 @@ private function createDownloadResponse(

$disposition = $response->headers->makeDisposition(
$forceDownload ? ResponseHeaderBag::DISPOSITION_ATTACHMENT : ResponseHeaderBag::DISPOSITION_INLINE,
$fileName
$this->sanitizeFileName($fileName)
);
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Type', $mimeType ?: 'application/octet-stream');

return $response;
}

private function sanitizeFileName(string $fileName): string
{
return str_replace(
' ',
'_',
$fileName
);
}
}

0 comments on commit b754427

Please sign in to comment.