From 96e7349b070fbb3363e90b227437bc4f0a08d5b7 Mon Sep 17 00:00:00 2001 From: Prasun Joshi Date: Thu, 13 Aug 2020 02:48:58 +0530 Subject: [PATCH] update failing test and add more test to IsExistingEmail --- validator.go | 6 +++--- validator_test.go | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/validator.go b/validator.go index 298f992..a04bae2 100644 --- a/validator.go +++ b/validator.go @@ -84,13 +84,13 @@ func IsExistingEmail(email string) bool { if len(user) > 64 { return false } - if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) { - return false - } switch host { case "localhost", "example.com": return true } + if userDotRegexp.MatchString(user) || !userRegexp.MatchString(user) || !hostRegexp.MatchString(host) { + return false + } if _, err := net.LookupMX(host); err != nil { if _, err := net.LookupIP(host); err != nil { return false diff --git a/validator_test.go b/validator_test.go index 631dff0..d86acb6 100644 --- a/validator_test.go +++ b/validator_test.go @@ -653,7 +653,10 @@ func TestIsExistingEmail(t *testing.T) { {"@invalid.com", false}, {"NathAn.daVIeS@DomaIn.cOM", true}, {"NATHAN.DAVIES@DOMAIN.CO.UK", true}, - {"nosuchdomain@bar.coffee", false}, + {"prasun.joshi@localhost", true}, + {"[prasun.joshi]@DomaIn.cOM", false}, + {"sizeofuserismorethansixtyfour0123sizeofuserismorethansixtyfour0123@DOMAIN.CO.UK", false}, + {"nosuchdomain@bar.nosuchdomainsuffix", false}, } for _, test := range tests { actual := IsExistingEmail(test.param)