Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Validator] New extensions check of the File Constraint does not normalize the extensions #48859

Copy link
Copy link
Closed
@spackmat

Description

@spackmat
Issue body actions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.