Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
zjjhot committed Aug 3, 2023
2 parents 66b4a39 + 0827fbd commit 9c39987
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 13 deletions.
3 changes: 1 addition & 2 deletions docs/content/administration/email-setup.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ SMTP_PORT = 465
FROM = [email protected]
USER = example.user
PASSWD = `***`
PROTOCOL = smtp
IS_TLS_ENABLED = true
PROTOCOL = smtps
```

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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ require (
github.com/yuin/goldmark-meta v1.1.0
golang.org/x/crypto v0.11.0
golang.org/x/image v0.9.0
golang.org/x/net v0.12.0
golang.org/x/net v0.13.0
golang.org/x/oauth2 v0.10.0
golang.org/x/sys v0.10.0
golang.org/x/text v0.11.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1216,8 +1216,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/net v0.13.0 h1:Nvo8UFsZ8X3BhAC9699Z1j7XQ3rsZnUUm7jfBEk1ueY=
golang.org/x/net v0.13.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
Expand Down
2 changes: 1 addition & 1 deletion models/repo/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func init() {
db.RegisterModel(new(RepoTopic))
}

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

// Topic represents a topic of repositories
type Topic struct {
Expand Down
2 changes: 2 additions & 0 deletions models/repo/topic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func TestAddTopic(t *testing.T) {
func TestTopicValidator(t *testing.T) {
assert.True(t, repo_model.ValidateTopic("12345"))
assert.True(t, repo_model.ValidateTopic("2-test"))
assert.True(t, repo_model.ValidateTopic("foo.bar"))
assert.True(t, repo_model.ValidateTopic("test-3"))
assert.True(t, repo_model.ValidateTopic("first"))
assert.True(t, repo_model.ValidateTopic("second-test-topic"))
Expand All @@ -77,4 +78,5 @@ func TestTopicValidator(t *testing.T) {
assert.False(t, repo_model.ValidateTopic("$fourth-test,topic"))
assert.False(t, repo_model.ValidateTopic("-fifth-test-topic"))
assert.False(t, repo_model.ValidateTopic("sixth-go-project-topic-with-excess-length"))
assert.False(t, repo_model.ValidateTopic(".foo"))
}
10 changes: 5 additions & 5 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1150,10 +1150,10 @@ file_view_rendered = View Rendered
file_view_raw = View Raw
file_permalink = Permalink
file_too_large = The file is too large to be shown.
invisible_runes_header = `This file contains invisible Unicode characters!`
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.`
ambiguous_runes_header = `This file contains ambiguous Unicode characters!`
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.`
invisible_runes_header = `This file contains invisible Unicode characters`
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.`
ambiguous_runes_header = `This file contains ambiguous Unicode characters`
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.`
invisible_runes_line = `This line has invisible unicode characters`
ambiguous_runes_line = `This line has ambiguous unicode characters`
ambiguous_character = `%[1]c [U+%04[1]X] can be confused with %[2]c [U+%04[2]X]`
Expand Down Expand Up @@ -2507,7 +2507,7 @@ tag.create_success = Tag "%s" has been created.
topic.manage_topics = Manage Topics
topic.done = Done
topic.count_prompt = You cannot select more than 25 topics
topic.format_prompt = Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
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.

find_file.go_to_file = Go to file
find_file.no_matching = No matching file found
Expand Down
64 changes: 64 additions & 0 deletions services/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
package user

import (
"fmt"
"path/filepath"
"strings"
"testing"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/auth"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
repo_model "code.gitea.io/gitea/models/repo"
Expand Down Expand Up @@ -94,6 +97,67 @@ func TestCreateUser(t *testing.T) {
assert.NoError(t, DeleteUser(db.DefaultContext, user, false))
}

func TestRenameUser(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 21})

t.Run("Non-Local", func(t *testing.T) {
u := &user_model.User{
Type: user_model.UserTypeIndividual,
LoginType: auth.OAuth2,
}
assert.ErrorIs(t, RenameUser(db.DefaultContext, u, "user_rename"), user_model.ErrUserIsNotLocal{})
})

t.Run("Same username", func(t *testing.T) {
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, user.Name), user_model.ErrUsernameNotChanged{UID: user.ID, Name: user.Name})
})

t.Run("Non usable username", func(t *testing.T) {
usernames := []string{"--diff", "aa.png", ".well-known", "search", "aaa.atom"}
for _, username := range usernames {
t.Run(username, func(t *testing.T) {
assert.Error(t, user_model.IsUsableUsername(username))
assert.Error(t, RenameUser(db.DefaultContext, user, username))
})
}
})

t.Run("Only capitalization", func(t *testing.T) {
caps := strings.ToUpper(user.Name)
unittest.AssertNotExistsBean(t, &user_model.User{ID: user.ID, Name: caps})
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: user.Name})

assert.NoError(t, RenameUser(db.DefaultContext, user, caps))

unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: user.ID, Name: caps})
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: caps})
})

t.Run("Already exists", func(t *testing.T) {
existUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})

assert.ErrorIs(t, RenameUser(db.DefaultContext, user, existUser.Name), user_model.ErrUserAlreadyExist{Name: existUser.Name})
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, existUser.LowerName), user_model.ErrUserAlreadyExist{Name: existUser.LowerName})
newUsername := fmt.Sprintf("uSEr%d", existUser.ID)
assert.ErrorIs(t, RenameUser(db.DefaultContext, user, newUsername), user_model.ErrUserAlreadyExist{Name: newUsername})
})

t.Run("Normal", func(t *testing.T) {
oldUsername := user.Name
newUsername := "User_Rename"

assert.NoError(t, RenameUser(db.DefaultContext, user, newUsername))
unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: user.ID, Name: newUsername, LowerName: strings.ToLower(newUsername)})

redirectUID, err := user_model.LookupUserRedirect(oldUsername)
assert.NoError(t, err)
assert.EqualValues(t, user.ID, redirectUID)

unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: user.ID, OwnerName: user.Name})
})
}

func TestCreateUser_Issue5882(t *testing.T) {
// Init settings
_ = setting.Admin
Expand Down
12 changes: 12 additions & 0 deletions services/wiki/wiki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,15 @@ func TestPrepareWikiFileName_FirstPage(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, "Home.md", newWikiPath)
}

func TestWebPathConversion(t *testing.T) {
assert.Equal(t, "path/wiki", WebPathToURLPath(WebPath("path/wiki")))
assert.Equal(t, "wiki", WebPathToURLPath(WebPath("wiki")))
assert.Equal(t, "", WebPathToURLPath(WebPath("")))
}

func TestWebPathFromRequest(t *testing.T) {
assert.Equal(t, WebPath("a%2Fb"), WebPathFromRequest("a/b"))
assert.Equal(t, WebPath("a"), WebPathFromRequest("a"))
assert.Equal(t, WebPath("b"), WebPathFromRequest("a/../b"))
}
2 changes: 1 addition & 1 deletion templates/repo/unicode_escape_prompt.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{if .EscapeStatus}}
{{if .EscapeStatus.HasInvisible}}
<div class="ui error message unicode-escape-prompt gt-text-left">
<div class="ui warning message unicode-escape-prompt gt-text-left">
<button class="close icon hide-panel button" data-panel-closest=".message">{{svg "octicon-x" 16 "close inside"}}</button>
<div class="header">
{{$.root.locale.Tr "repo.invisible_runes_header"}}
Expand Down
2 changes: 1 addition & 1 deletion web_src/js/features/repo-home.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export function initRepoTopicBar() {
rules: [
{
type: 'validateTopic',
value: /^[a-z0-9][a-z0-9-]{0,35}$/,
value: /^\s*[a-z0-9][-.a-z0-9]{0,35}\s*$/,
prompt: topicPrompts.formatPrompt
},
{
Expand Down

0 comments on commit 9c39987

Please sign in to comment.