-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected
6.2.4
Description
Hi, the new extensions
config for the File Constraint does not normalize the checked extensions, nor the configured ones). So for example, when I allow the 'xml' extension and someone uploads a valid XML-file called 'MY.XML', that is considered as invalid.
As a workaround, I can also configure XML
as a second allowed extension, but then someone will come and upload a 'My.Xml' next and so forth. Many smartphones name their camera files with uppercased extensions, so more often that should affect the jpg
or m4v
extensions.
How to reproduce
Configure a File Constraint and set the extensions
config:
new File(
extensions: ['xml'],
),
Then upload an XML-file with a non-lowercase file-extension like xml.XML
and observe that it is considered as a not allowed file-extension. Validate that by renaming it to xml.xml
, upload it again and observe that it is considered as an allowed file-extension.
Or just have a look into the code of the FileValidator.php inside the block starting with if ($constraint->extensions) {
to see how the check is currently implemented.
Possible Solution
From my point of view, the check should instead of if ($fileExtension !== $k)
do something like if (mb_strtolower($fileExtension) !== mb_strtolower($k))
or normalize the checked (and configured) extensions in any other way so that the check is case-insensitive.
I could send a PR for that, if that would be an accepted solution.
Additional Context
No response