dchest / validator

Go package validator validates and normalizes email addresses and domain names.
http://godoc.org/github.com/dchest/validator
BSD 2-Clause "Simplified" License
17 stars 2 forks source link

NormalizeEmail implementation conflicts with IsValidEmail #1

Open tv42 opened 5 years ago

tv42 commented 5 years ago

NormalizeEmail wants to trim trailing periods: https://github.com/dchest/validator/blob/6e75c8ee02d3b9e46121fe1e0dbee699b5523ca3/email.go#L107-L108

But before it gets there, it calls IsValidEmail: https://github.com/dchest/validator/blob/6e75c8ee02d3b9e46121fe1e0dbee699b5523ca3/email.go#L99

and IsValidEmail's regexp refuses to accept a trailing dot.

Thus, NormalizeEmail refuses to normalize away a trailing period: https://play.golang.org/p/qGQGN3AKQV8

dchest commented 5 years ago

Thanks for catching this! Here's a good discussion about trailing dot in the domain name of email addresses — in practice, it's not supported. So, I'd leave the validator as-is, marking such addresses invalid. In that case, the dot removal in normalizer should go. But... it does no harm apart spending a few cycles, so I'm kinda torn between removing it and keeping it as a defensive programming technique, just as a reminder that normalizer should remove it (maybe add a comment saying that it's not functional?) or in case someone copies this code and use it without validator.