FileExtensionAttributeAdapter Fails jQuery Validation
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 281
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Describe the bug
When using the `FileExtensionAttribute` on an `IFormFile`, the `data-val-fileextensions-extensions` attribute is not constructed per jQuery documentation https://jqueryvalidation.org/extension-method/. The client-side validation always fails because each file extension is prefixed with a period.
https://github.com/dotnet/aspnetcore/blob/bce4dd5ff65a4d2089c3e20761ba34f3f403ef37/src/Mvc/Mvc.DataAnnotations/src/FileExtensionsAttributeAdapter.cs#L19-L26
https://github.com/dotnet/aspnetcore/blob/bce4dd5ff65a4d2089c3e20761ba34f3f403ef37/src/Mvc/Mvc.DataAnnotations/src/FileExtensionsAttributeAdapter.cs#L36
jQuery validation expects the file extensions to be given as comma or pipe-delimited without periods or spaces so they can be matched using RegEx.
https://github.com/jquery-validation/jquery-validation/blob/6cd68f68e395b1c3a2588e6e7d64f561410c2dc0/src/additional/extension.js#L2-L4
The normalized list of comma-delimited extensions should be used for the attribute instead of `_extensions`.
https://github.com/dotnet/aspnetcore/blob/bce4dd5ff65a4d2089c3e20761ba34f3f403ef37/src/Mvc/Mvc.DataAnnotations/src/FileExtensionsAttributeAdapter.cs#L23
### Expected Behavior
_No response_
### Steps To Reproduce
_No response_
### Exceptions (if any)
In jquery-validation 1.13.1 and older, this issue likely went mostly unnoticed due to a bug (This was fixed in jquery-validation 1.14.0)
### .NET Version
_No response_
### Anything else?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.