Skip to content

Commit 08d9845

Browse files
authored
use proper subaddress (#36639)
1 parent 4ca4217 commit 08d9845

4 files changed

Lines changed: 15 additions & 13 deletions

File tree

models/user/user.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func (u *User) SetLastLogin() {
213213

214214
// GetPlaceholderEmail returns an noreply email
215215
func (u *User) GetPlaceholderEmail() string {
216-
return fmt.Sprintf("%s+%d@%s", u.LowerName, u.ID, setting.Service.NoReplyAddress)
216+
return fmt.Sprintf("%d+%s@%s", u.ID, u.LowerName, setting.Service.NoReplyAddress)
217217
}
218218

219219
// GetEmail returns a noreply email, if the user has set to keep his
@@ -1279,13 +1279,15 @@ func GetUsersByEmails(ctx context.Context, emails []string) (*EmailUserMap, erro
12791279
return &EmailUserMap{results}, nil
12801280
}
12811281

1282-
// parseLocalPartToNameID attempts to unparse local-part of email that's in format user+id
1282+
// parseLocalPartToNameID attempts to unparse local-part of email that's in format id+user
12831283
// returns user and id if possible
12841284
func parseLocalPartToNameID(localPart string) (string, int64) {
12851285
var id int64
1286-
name, idstr, hasPlus := strings.Cut(localPart, "+")
1286+
idstr, name, hasPlus := strings.Cut(localPart, "+")
12871287
if hasPlus {
12881288
id, _ = strconv.ParseInt(idstr, 10, 64)
1289+
} else {
1290+
name = idstr
12891291
}
12901292
return name, id
12911293
}

models/user/user_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func TestUserEmails(t *testing.T) {
6666
{"UseR1@example.com", 1},
6767
{"user1-2@example.COM", 1},
6868
{"USER2@" + setting.Service.NoReplyAddress, 2},
69-
{"user2+2@" + setting.Service.NoReplyAddress, 2},
70-
{"oldUser2UsernameWhichDoesNotMatterForQuery+2@" + setting.Service.NoReplyAddress, 2},
71-
{"badUser+99999@" + setting.Service.NoReplyAddress, 0},
69+
{"2+user2@" + setting.Service.NoReplyAddress, 2},
70+
{"2+oldUser2UsernameWhichDoesNotMatterForQuery@" + setting.Service.NoReplyAddress, 2},
71+
{"99999+badUser@" + setting.Service.NoReplyAddress, 0},
7272
{"user4@example.com", 4},
7373
{"no-such", 0},
7474
}

tests/integration/editor_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ func testEditorWebGitCommitEmail(t *testing.T) {
258258
t.Run("DefaultEmailKeepPrivate", func(t *testing.T) {
259259
defer tests.PrintCurrentTest(t)()
260260
paramsForKeepPrivate["commit_email"] = ""
261-
resp1 = makeReq(t, linkForKeepPrivate, paramsForKeepPrivate, "User Two", "user2+2@noreply.example.org")
261+
resp1 = makeReq(t, linkForKeepPrivate, paramsForKeepPrivate, "User Two", "2+user2@noreply.example.org")
262262
})
263263
t.Run("ChooseEmail", func(t *testing.T) {
264264
defer tests.PrintCurrentTest(t)()

tests/integration/repofiles_change_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,14 @@ func getExpectedFileResponseForRepoFilesCreate(commitID string, lastCommit *git.
132132
Author: &api.CommitUser{
133133
Identity: api.Identity{
134134
Name: "User Two",
135-
Email: "user2+2@noreply.example.org",
135+
Email: "2+user2@noreply.example.org",
136136
},
137137
Date: time.Now().UTC().Format(time.RFC3339),
138138
},
139139
Committer: &api.CommitUser{
140140
Identity: api.Identity{
141141
Name: "User Two",
142-
Email: "user2+2@noreply.example.org",
142+
Email: "2+user2@noreply.example.org",
143143
},
144144
Date: time.Now().UTC().Format(time.RFC3339),
145145
},
@@ -202,14 +202,14 @@ func getExpectedFileResponseForRepoFilesUpdate(commitID, filename, lastCommitSHA
202202
Author: &api.CommitUser{
203203
Identity: api.Identity{
204204
Name: "User Two",
205-
Email: "user2+2@noreply.example.org",
205+
Email: "2+user2@noreply.example.org",
206206
},
207207
Date: time.Now().UTC().Format(time.RFC3339),
208208
},
209209
Committer: &api.CommitUser{
210210
Identity: api.Identity{
211211
Name: "User Two",
212-
Email: "user2+2@noreply.example.org",
212+
Email: "2+user2@noreply.example.org",
213213
},
214214
Date: time.Now().UTC().Format(time.RFC3339),
215215
},
@@ -312,13 +312,13 @@ func getExpectedFileResponseForRepoFilesUpdateRename(commitID, lastCommitSHA str
312312
Author: &api.CommitUser{
313313
Identity: api.Identity{
314314
Name: "User Two",
315-
Email: "user2+2@noreply.example.org",
315+
Email: "2+user2@noreply.example.org",
316316
},
317317
},
318318
Committer: &api.CommitUser{
319319
Identity: api.Identity{
320320
Name: "User Two",
321-
Email: "user2+2@noreply.example.org",
321+
Email: "2+user2@noreply.example.org",
322322
},
323323
},
324324
Parents: []*api.CommitMeta{

0 commit comments

Comments
 (0)