From dd4642813bdabafb37436a3a9639ffbe3f9cc34e Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 23 Dec 2015 00:08:51 -0800 Subject: [PATCH] Ignore spaces in authorized emails list --- validator.go | 3 ++- validator_test.go | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/validator.go b/validator.go index e3c0a54..1b04923 100644 --- a/validator.go +++ b/validator.go @@ -53,7 +53,8 @@ func (um *UserMap) LoadAuthenticatedEmailsFile() { } updated := make(map[string]bool) for _, r := range records { - updated[strings.ToLower(r[0])] = true + address := strings.ToLower(strings.TrimSpace(r[0])) + updated[address] = true } atomic.StorePointer(&um.m, unsafe.Pointer(&updated)) } diff --git a/validator_test.go b/validator_test.go index 0bf0a08..b87d419 100644 --- a/validator_test.go +++ b/validator_test.go @@ -147,3 +147,16 @@ func TestValidatorComparisonsAreCaseInsensitive(t *testing.T) { t.Error("validated domains are not lower-cased") } } + +func TestValidatorIgnoreSpacesInAuthEmails(t *testing.T) { + vt := NewValidatorTest(t) + defer vt.TearDown() + + vt.WriteEmails(t, []string{" foo.bar@example.com "}) + domains := []string(nil) + validator := vt.NewValidator(domains, nil) + + if !validator("foo.bar@example.com") { + t.Error("email should validate") + } +}