-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix(useDropZone): validate all file types individually when dropping multiple files #4325
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
Conversation
If you upload multiple files and one of them is invalid, all files will be added
Hey, can you try the demo result? It doesn't seem to work. -.Compressed.with.FlexClip.mp4 |
This bug seems to come from the demo, if you try with real images and svgs everything works fine Check out this video: Screen.Recording.2024-11-05.at.5.55.18.PM.mp4 |
Sorry, can you test it in Safari? After testing, it works well in Chrome, but in Safari, Please correct me if I'm wrong. |
Yes you are right, we must invalidate if no type is found in the DataTransferList. I just updated the code : For Safari, the limitation is that we can check the validity of the files only during the drop event. For other events (drag*), the event.dataTransfer is not transmitted. Concerning the demo, the HTMLElement drop is not a good use case. When using PNG and SVG in HTMLElement, the dataTransfer has several items and therefore several types (e.g. 'text/uri-list', 'text/html', 'image/png' for PNG) because we drag an HTMLElement. |
I agree, I'm looking forward to this PR being merged! |
Before submitting the PR, please make sure you do the following
fixes #123
).Description
This PR fixes a bug in the
useDropzone
composable related to file type validation. Previously, the validation would pass if any of the dropped files matched any of the allowed types, potentially allowing invalid file types to be accepted.Bug details:
some()
method checks if any file type matches the allowed types, making the validation pass even if some files don't match the criteriaFix:
checkDataTypes
function to validate each file type individuallyAdditional context
The fix changes the validation approach from an any-match to an all-match strategy, which better aligns with expected dropzone behavior. This is particularly important for security-conscious applications where file type validation is critical.
Example of the issue:
If allowed types are
['image/jpg', 'image/png']
and someone drops both a.jpg
and.exe
file, the previous implementation would incorrectly validate this as acceptable because at least one file (the.jpg
) matched the criteria.