Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

fix: lowercase the email before hashing the Gravatar URL

Andy-Sverdlov-LucaNet7f226dcd096b
diff --git a/pkg/gravatar/gravatar.go b/pkg/gravatar/gravatar.go
index 9c79b387..30874f15 100644
--- a/pkg/gravatar/gravatar.go
+++ b/pkg/gravatar/gravatar.go
@@ -29,7 +29,7 @@ import (
// GetAvatarURL get avatar url from gravatar by email
func GetAvatarURL(baseURL, email string) string {
- hasher := sha256.Sum256([]byte(strings.TrimSpace(email)))
+ hasher := sha256.Sum256([]byte(strings.ToLower(strings.TrimSpace(email))))
hash := hex.EncodeToString(hasher[:])
return baseURL + hash
}
diff --git a/pkg/gravatar/gravatar_test.go b/pkg/gravatar/gravatar_test.go
index b88a6964..9a51773a 100644
--- a/pkg/gravatar/gravatar_test.go
+++ b/pkg/gravatar/gravatar_test.go
@@ -41,6 +41,21 @@ func TestGetAvatarURL(t *testing.T) {
args: args{email: "[email protected]"},
want: "https://www.gravatar.com/avatar/7296942c1f63d97f6c124705142009867638f7b3dbcdadd0cb1bcb40e427eb8e",
},
+ {
+ name: "mixed case address",
+ args: args{email: "[email protected]"},
+ want: "https://www.gravatar.com/avatar/7296942c1f63d97f6c124705142009867638f7b3dbcdadd0cb1bcb40e427eb8e",
+ },
+ {
+ name: "upper case address",
+ args: args{email: "[email protected]"},
+ want: "https://www.gravatar.com/avatar/7296942c1f63d97f6c124705142009867638f7b3dbcdadd0cb1bcb40e427eb8e",
+ },
+ {
+ name: "padded mixed case address",
+ args: args{email: " [email protected] "},
+ want: "https://www.gravatar.com/avatar/7296942c1f63d97f6c124705142009867638f7b3dbcdadd0cb1bcb40e427eb8e",
+ },
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {