Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File naming (file extensions) changed between 2.4.1 and 2.4.2 #1479

Closed
jxmallett opened this issue Nov 27, 2024 · 6 comments · Fixed by #1484
Closed

File naming (file extensions) changed between 2.4.1 and 2.4.2 #1479

jxmallett opened this issue Nov 27, 2024 · 6 comments · Fixed by #1484

Comments

@jxmallett
Copy link

jxmallett commented Nov 27, 2024

BC Break Report

Q A
BC Break yes
Version 2.4.2

Summary

The handling of file extensions changed in 2.4.2 with this commit 4962a3e (Specifically the changes to the FileExtensionTrait)

Previous behavior

Previously the file extension was based on the extension of the original name of the uploaded file.

Current behavior

The original file extension is now ignored and the extension is 'guessed' based on the mime type.

How to reproduce

  • Create a zip file (of any file) and name it zip-file.txt.
  • Check the mime type in bash with file -i zip-file.txt. It should return application/zip.
  • Upload zip-file.txt using vich uploader. I am using the UniqidNamer, but any namer that uses FileExtensionTrait is affected.
  • Observe the .txt extension is removed and replaced with .zip

I know the commit was made to address a potential security issue, but I thought the behaviour change was worth reporting.

@ServerExe
Copy link

I have the same issues with CSV files now. They result in .txt files which is not acceptable for us

@garak
Copy link
Collaborator

garak commented Dec 11, 2024

I have the same issues with CSV files now. They result in .txt files which is not acceptable for us

This is either a problem with symfony/mime component or with your file having the wrong mime type

@ServerExe
Copy link

This is either a problem with symfony/mime component or with your file having the wrong mime type

Simple CSV files are always considered text/plain. At least when you export an Excel file to an UTF-8 CSV File. Symfony's MimeTypes class maps text/plain to .txt.

I guess I will need to write a custom Namer since I need the uploaded files to keep their extension.

@garak
Copy link
Collaborator

garak commented Dec 12, 2024

I guess I will need to write a custom Namer since I need the uploaded files to keep their extension.

A possible improvement to the bundle could be adding a new option, something like namer_keep_extension: if true, it would behave like the old one, if false like the current one. The default should be false.

PRs are welcome.

@garak
Copy link
Collaborator

garak commented Dec 13, 2024

About a possible alternate solution: we could add a map of extensions allowed for reach mime type, and then keep the original extension when it belongs to that list. Probably easier.

@garak
Copy link
Collaborator

garak commented Dec 14, 2024

The change in the proposed PR should fix the problem with the CSV extension. If you have more cases to add, feel free to suggest them.
The same PR also adds a few documentation notes about the upgrade process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants