fix: email comments are removed from email addresses (#9074)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9074
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2025-08-30 13:15:30 +02:00
commit 1b13fda06b
9 changed files with 99 additions and 21 deletions

View file

@ -109,7 +109,7 @@ func (f *RegisterForm) Validate(req *http.Request, errs binding.Errors) binding.
// The email is marked as allowed if it matches any of the
// domains in the whitelist or if it doesn't match any of
// domains in the blocklist, if any such list is not empty.
func (f *RegisterForm) IsEmailDomainAllowed() bool {
func (f *RegisterForm) IsEmailDomainAllowed() (validEmail, ok bool) {
return validation.IsEmailDomainAllowed(f.Email)
}

View file

@ -20,7 +20,9 @@ func TestRegisterForm_IsDomainAllowed_Empty(t *testing.T) {
form := RegisterForm{}
assert.True(t, form.IsEmailDomainAllowed())
emailValid, ok := form.IsEmailDomainAllowed()
assert.False(t, emailValid)
assert.False(t, ok)
}
func TestRegisterForm_IsDomainAllowed_InvalidEmail(t *testing.T) {
@ -36,7 +38,8 @@ func TestRegisterForm_IsDomainAllowed_InvalidEmail(t *testing.T) {
for _, v := range tt {
form := RegisterForm{Email: v.email}
assert.False(t, form.IsEmailDomainAllowed())
_, ok := form.IsEmailDomainAllowed()
assert.False(t, ok)
}
}
@ -59,7 +62,8 @@ func TestRegisterForm_IsDomainAllowed_AllowedEmail(t *testing.T) {
for _, v := range tt {
form := RegisterForm{Email: v.email}
assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
_, ok := form.IsEmailDomainAllowed()
assert.Equal(t, v.valid, ok)
}
}
@ -72,7 +76,6 @@ func TestRegisterForm_IsDomainAllowed_BlockedEmail(t *testing.T) {
}{
{"security@gitea.io", false},
{"security@gitea.example", true},
{"invalid", true},
{"user@my.block", false},
{"user@my.block1", true},
@ -81,7 +84,8 @@ func TestRegisterForm_IsDomainAllowed_BlockedEmail(t *testing.T) {
for _, v := range tt {
form := RegisterForm{Email: v.email}
assert.Equal(t, v.valid, form.IsEmailDomainAllowed())
_, ok := form.IsEmailDomainAllowed()
assert.Equal(t, v.valid, ok)
}
}