]> source.dussan.org Git - gitea.git/commitdiff
HashEmail function should also remove spaces
authorAndrew Burns <ErebusBat@gmail.com>
Fri, 5 Dec 2014 17:58:49 +0000 (10:58 -0700)
committerAndrew Burns <ErebusBat@gmail.com>
Fri, 5 Dec 2014 17:58:49 +0000 (10:58 -0700)
According to the [Gravatar API](https://en.gravatar.com/site/implement/hash/) whitespace should also be removed from the email, it was not doing this previously.

modules/avatar/avatar.go

index 144fda387e50bf11d617e1f998c4723e53fe620c..225d6c8183019cf88f932a4038d201e11fac7d18 100644 (file)
@@ -48,8 +48,12 @@ func init() {
 // hash email to md5 string
 // keep this func in order to make this package indenpent
 func HashEmail(email string) string {
+       // https://en.gravatar.com/site/implement/hash/
+       email = strings.TrimSpace(email)
+       email = strings.ToLower(email)
+
        h := md5.New()
-       h.Write([]byte(strings.ToLower(email)))
+       h.Write([]byte(email))
        return hex.EncodeToString(h.Sum(nil))
 }