jstedfast / EmailValidation

A simple (but correct) .NET class for validating email addresses
MIT License
275 stars 70 forks source link

`EmailAttribute` should allow null values #41

Closed alexrp closed 1 year ago

alexrp commented 1 year ago

Specifically:

https://github.com/jstedfast/EmailValidation/blob/643a8e3cf3dd93f5eba60e27639728df8d3457a3/EmailValidation/EmailAttribute.cs#L86-L87

https://github.com/jstedfast/EmailValidation/blob/643a8e3cf3dd93f5eba60e27639728df8d3457a3/EmailValidation/EmailAttribute.cs#L105


Most (all?) attributes in System.ComponentModel.DataAnnotations of a similar nature to EmailAttribute consider null to be valid.

Examples:

Generally speaking, one should use RequiredAttribute if a value should not be allowed to be null. (Higher-level frameworks like ASP.NET Core will additionally use C# nullability annotations to infer RequiredAttribute.)

alexrp commented 1 year ago

(Aside: The allocation of memberNames is pointless in the success case.)

jstedfast commented 1 year ago

Seems reasonable. Hopefully won't break any existing apps due to a change in expectations.