Skip to content

Commit 9c39987

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Make confusable character warning less jarring (go-gitea#25069) Update Gmail example (go-gitea#26302) Fix the topic validation rule and suport dots (go-gitea#26286) Upgrade x/net to 0.13.0 (go-gitea#26297) add unit test for user renaming (go-gitea#26261) add some Wiki unit tests (go-gitea#26260)
2 parents 66b4a39 + 0827fbd commit 9c39987

File tree

10 files changed

+90
-13
lines changed

10 files changed

+90
-13
lines changed

docs/content/administration/email-setup.en-us.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ SMTP_PORT = 465
7979
8080
USER = example.user
8181
PASSWD = `***`
82-
PROTOCOL = smtp
83-
IS_TLS_ENABLED = true
82+
PROTOCOL = smtps
8483
```
8584

8685
Note that you'll need to create and use an [App password](https://support.google.com/accounts/answer/185833?hl=en) by enabling 2FA on your Google

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ require (
107107
github.com/yuin/goldmark-meta v1.1.0
108108
golang.org/x/crypto v0.11.0
109109
golang.org/x/image v0.9.0
110-
golang.org/x/net v0.12.0
110+
golang.org/x/net v0.13.0
111111
golang.org/x/oauth2 v0.10.0
112112
golang.org/x/sys v0.10.0
113113
golang.org/x/text v0.11.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,8 +1216,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
12161216
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
12171217
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
12181218
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
1219-
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
1220-
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
1219+
golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY=
1220+
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
12211221
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
12221222
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
12231223
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=

models/repo/topic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func init() {
2222
db.RegisterModel(new(RepoTopic))
2323
}
2424

25-
var topicPattern = regexp.MustCompile(`^[a-z0-9][a-z0-9-]*$`)
25+
var topicPattern = regexp.MustCompile(`^[a-z0-9][-.a-z0-9]*$`)
2626

2727
// Topic represents a topic of repositories
2828
type Topic struct {

models/repo/topic_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func TestAddTopic(t *testing.T) {
6969
func TestTopicValidator(t *testing.T) {
7070
assert.True(t, repo_model.ValidateTopic("12345"))
7171
assert.True(t, repo_model.ValidateTopic("2-test"))
72+
assert.True(t, repo_model.ValidateTopic("foo.bar"))
7273
assert.True(t, repo_model.ValidateTopic("test-3"))
7374
assert.True(t, repo_model.ValidateTopic("first"))
7475
assert.True(t, repo_model.ValidateTopic("second-test-topic"))
@@ -77,4 +78,5 @@ func TestTopicValidator(t *testing.T) {
7778
assert.False(t, repo_model.ValidateTopic("$fourth-test,topic"))
7879
assert.False(t, repo_model.ValidateTopic("-fifth-test-topic"))
7980
assert.False(t, repo_model.ValidateTopic("sixth-go-project-topic-with-excess-length"))
81+
assert.False(t, repo_model.ValidateTopic(".foo"))
8082
}

options/locale/locale_en-US.ini

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,10 +1150,10 @@ file_view_rendered = View Rendered
11501150
file_view_raw = View Raw
11511151
file_permalink = Permalink
11521152
file_too_large = The file is too large to be shown.
1153-
invisible_runes_header = `This file contains invisible Unicode characters!`
1154-
invisible_runes_description = `This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.`
1155-
ambiguous_runes_header = `This file contains ambiguous Unicode characters!`
1156-
ambiguous_runes_description = `This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.`
1153+
invisible_runes_header = `This file contains invisible Unicode characters`
1154+
invisible_runes_description = `This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.`
1155+
ambiguous_runes_header = `This file contains ambiguous Unicode characters`
1156+
ambiguous_runes_description = `This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.`
11571157
invisible_runes_line = `This line has invisible unicode characters`
11581158
ambiguous_runes_line = `This line has ambiguous unicode characters`
11591159
ambiguous_character = `%[1]c [U+%04[1]X] can be confused with %[2]c [U+%04[2]X]`
@@ -2507,7 +2507,7 @@ tag.create_success = Tag "%s" has been created.
25072507
topic.manage_topics = Manage Topics
25082508
topic.done = Done
25092509
topic.count_prompt = You cannot select more than 25 topics
2510-
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2510+
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and dots ('.'), can be up to 35 characters long. Letters must be lowercase.
25112511

25122512
find_file.go_to_file = Go to file
25132513
find_file.no_matching = No matching file found

services/user/user_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
package user
55

66
import (
7+
"fmt"
78
"path/filepath"
9+
"strings"
810
"testing"
911

1012
"code.gitea.io/gitea/models"
13+
"code.gitea.io/gitea/models/auth"
1114
"code.gitea.io/gitea/models/db"
1215
"code.gitea.io/gitea/models/organization"
1316
repo_model "code.gitea.io/gitea/models/repo"
@@ -94,6 +97,67 @@ func TestCreateUser(t *testing.T) {
9497
assert.NoError(t, DeleteUser(db.DefaultContext, user, false))
9598
}
9699

100+
func TestRenameUser(t *testing.T) {
101+
assert.NoError(t, unittest.PrepareTestDatabase())
102+
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 21})
103+
104+
t.Run("Non-Local", func(t *testing.T) {
105+
u := &user_model.User{
106+
Type: user_model.UserTypeIndividual,
107+
LoginType: auth.OAuth2,
108+
}
109+
assert.ErrorIs(t, RenameUser(db.DefaultContext, u, "user_rename"), user_model.ErrUserIsNotLocal{})
110+
})
111+
112+
t.Run("Same username", func(t *testing.T) {
113+
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, user.Name), user_model.ErrUsernameNotChanged{UID: user.ID, Name: user.Name})
114+
})
115+
116+
t.Run("Non usable username", func(t *testing.T) {
117+
usernames := []string{"--diff", "aa.png", ".well-known", "search", "aaa.atom"}
118+
for _, username := range usernames {
119+
t.Run(username, func(t *testing.T) {
120+
assert.Error(t, user_model.IsUsableUsername(username))
121+
assert.Error(t, RenameUser(db.DefaultContext, user, username))
122+
})
123+
}
124+
})
125+
126+
t.Run("Only capitalization", func(t *testing.T) {
127+
caps := strings.ToUpper(user.Name)
128+
unittest.AssertNotExistsBean(t, &user_model.User{ID: user.ID, Name: caps})
129+
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: user.Name})
130+
131+
assert.NoError(t, RenameUser(db.DefaultContext, user, caps))
132+
133+
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: user.ID, Name: caps})
134+
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: caps})
135+
})
136+
137+
t.Run("Already exists", func(t *testing.T) {
138+
existUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
139+
140+
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, existUser.Name), user_model.ErrUserAlreadyExist{Name: existUser.Name})
141+
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, existUser.LowerName), user_model.ErrUserAlreadyExist{Name: existUser.LowerName})
142+
newUsername := fmt.Sprintf("uSEr%d", existUser.ID)
143+
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, newUsername), user_model.ErrUserAlreadyExist{Name: newUsername})
144+
})
145+
146+
t.Run("Normal", func(t *testing.T) {
147+
oldUsername := user.Name
148+
newUsername := "User_Rename"
149+
150+
assert.NoError(t, RenameUser(db.DefaultContext, user, newUsername))
151+
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: user.ID, Name: newUsername, LowerName: strings.ToLower(newUsername)})
152+
153+
redirectUID, err := user_model.LookupUserRedirect(oldUsername)
154+
assert.NoError(t, err)
155+
assert.EqualValues(t, user.ID, redirectUID)
156+
157+
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: user.Name})
158+
})
159+
}
160+
97161
func TestCreateUser_Issue5882(t *testing.T) {
98162
// Init settings
99163
_ = setting.Admin

services/wiki/wiki_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,3 +307,15 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) {
307307
assert.NoError(t, err)
308308
assert.EqualValues(t, "Home.md", newWikiPath)
309309
}
310+
311+
func TestWebPathConversion(t *testing.T) {
312+
assert.Equal(t, "path/wiki", WebPathToURLPath(WebPath("path/wiki")))
313+
assert.Equal(t, "wiki", WebPathToURLPath(WebPath("wiki")))
314+
assert.Equal(t, "", WebPathToURLPath(WebPath("")))
315+
}
316+
317+
func TestWebPathFromRequest(t *testing.T) {
318+
assert.Equal(t, WebPath("a%2Fb"), WebPathFromRequest("a/b"))
319+
assert.Equal(t, WebPath("a"), WebPathFromRequest("a"))
320+
assert.Equal(t, WebPath("b"), WebPathFromRequest("a/../b"))
321+
}

templates/repo/unicode_escape_prompt.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{if .EscapeStatus}}
22
{{if .EscapeStatus.HasInvisible}}
3-
<div class="ui error message unicode-escape-prompt gt-text-left">
3+
<div class="ui warning message unicode-escape-prompt gt-text-left">
44
<button class="close icon hide-panel button" data-panel-closest=".message">{{svg "octicon-x" 16 "close inside"}}</button>
55
<div class="header">
66
{{$.root.locale.Tr "repo.invisible_runes_header"}}

web_src/js/features/repo-home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export function initRepoTopicBar() {
166166
rules: [
167167
{
168168
type: 'validateTopic',
169-
value: /^[a-z0-9][a-z0-9-]{0,35}$/,
169+
value: /^\s*[a-z0-9][-.a-z0-9]{0,35}\s*$/,
170170
prompt: topicPrompts.formatPrompt
171171
},
172172
{

0 commit comments

Comments
 (0)