Hello and thanks for the module!
I have an edge case issue in mind, so I think this is a minor thing.
Problem/Motivation
When a user is requesting a file and they try to give a string as file id, it will cause a PHP exception.
TypeError: Drupal\file_download\Controller\FileDownloadDownloadController::deliver(): Argument #3 ($fid) must be of type int, string given in Drupal\file_download\Controller\FileDownloadDownloadController->deliver() (line 37 of /var/www/html/web/modules/contrib/file_download/src/Controller/FileDownloadDownloadController.php).
I would rather have it throw the NotFoundHttpException() instead of giving a php error. This comes up every now and then especially when different bots/crawlers try random urls. Sometimes they hit these file download links too and this will cause php errors appearing in logs.
Steps to reproduce
For example when requesting /file-download/download/public/test-file instead of /file-download/download/public/5561
Proposed resolution
Maybe we could have a union type hint in deliver() method and also do a small variable check afterwards?
Something like this?
public function deliver(Request $request, string $scheme, int|string $fid): BinaryFileResponse|Response {
if (!$fid = filter_var($fid, FILTER_VALIDATE_INT)) {
throw new NotFoundHttpException();
}
Issue fork file_download-3557117
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
hartsak commentedI opened a merge request with some changes.
Please have a look!
Comment #5
shelaneThank you.