Skip to content

Commit 16b6f55

Browse files
authored
Merge branch 'master' into improve-strings
2 parents 76a00bf + ad2a288 commit 16b6f55

File tree

104 files changed

+1170
-801
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+1170
-801
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
* text=auto eol=lf
22
/vendor/** -text -eol linguist-vendored
33
/public/vendor/** -text -eol linguist-vendored
4+
/templates/**/*.tmpl linguist-language=Handlebars

.github/lock.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Configuration for Lock Threads - https://github.com/dessant/lock-threads-app
2+
3+
# Number of days of inactivity before a closed issue or pull request is locked
4+
daysUntilLock: 60
5+
6+
# Skip issues and pull requests created before a given timestamp. Timestamp must
7+
# follow ISO 8601 (`YYYY-MM-DD`). `false` is disabled
8+
skipCreatedBefore: false
9+
10+
# Issues and pull requests with these labels will be ignored.
11+
exemptLabels: []
12+
13+
# Label to add before locking, such as `outdated`. `false` is disabled
14+
lockLabel: false
15+
16+
# Comment to post before locking.
17+
lockComment: >
18+
This thread has been automatically locked since there has not been
19+
any recent activity after it was closed. Please open a new issue for
20+
related bugs and link to relevant comments in this thread.
21+
22+
# Assign `resolved` as the reason for locking. Set to `false` to disable
23+
setLockReason: true

Dockerfile.rootless

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ RUN mkdir -p /var/lib/gitea /etc/gitea
5050
RUN chown git:git /var/lib/gitea /etc/gitea
5151

5252
COPY docker/rootless /
53-
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
54-
RUN chown root:root /usr/local/bin/* && chmod 755 /usr/local/bin/*
53+
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
5554

5655
USER git:git
5756
ENV GITEA_WORK_DIR /var/lib/gitea

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ fomantic: $(FOMANTIC_DEST)
638638

639639
$(FOMANTIC_DEST): $(FOMANTIC_CONFIGS) | node_modules
640640
rm -rf $(FOMANTIC_DEST_DIR)
641-
cp web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
642-
cp -r web_src/fomantic/_site/* node_modules/fomantic-ui/src/_site/
641+
cp -f web_src/fomantic/theme.config.less node_modules/fomantic-ui/src/theme.config
642+
cp -rf web_src/fomantic/_site/* node_modules/fomantic-ui/src/_site/
643643
npx gulp -f node_modules/fomantic-ui/gulpfile.js build
644644
@touch $(FOMANTIC_DEST)
645645

cmd/web.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ func runWeb(ctx *cli.Context) error {
165165
return err
166166
}
167167
}
168-
// Set up Macaron
168+
// Set up Chi routes
169169
c := routes.NewChi()
170-
routes.RegisterRoutes(c)
170+
c.Mount("/", routes.NormalRoutes())
171+
routes.DelegateToMacaron(c)
171172

172173
err := listen(c, true)
173174
<-graceful.GetManager().Done()

contrib/pr/checkout.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ func runPR() {
118118
external.RegisterParsers()
119119
markup.Init()
120120
c := routes.NewChi()
121-
routes.RegisterRoutes(c)
121+
c.Mount("/", routes.NormalRoutes())
122+
routes.DelegateToMacaron(c)
122123

123124
log.Printf("[PR] Ready for testing !\n")
124125
log.Printf("[PR] Login with user1, user2, user3, ... with pass: password\n")

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ GRACEFUL_HAMMER_TIME = 60s
389389
; Allows the setting of a startup timeout and waithint for Windows as SVC service
390390
; 0 disables this.
391391
STARTUP_TIMEOUT = 0
392-
; Static resources, includes resources on custom/, public/ and all uploaded avatars web browser cache time, default is 6h
392+
; Static resources, includes resources on custom/, public/ and all uploaded avatars web browser cache time. Note that this cache is disabled when RUN_MODE is "dev". Default is 6h
393393
STATIC_CACHE_TIME = 6h
394394

395395
; Define allowed algorithms and their minimum key length (use -1 to disable a type)

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ Values containing `#` or `;` must be quoted using `` ` `` or `"""`.
262262
- `KEY_FILE`: **https/key.pem**: Key file path used for HTTPS. From 1.11 paths are relative to `CUSTOM_PATH`.
263263
- `STATIC_ROOT_PATH`: **./**: Upper level of template and static files path.
264264
- `APP_DATA_PATH`: **data** (**/data/gitea** on docker): Default path for application data.
265-
- `STATIC_CACHE_TIME`: **6h**: Web browser cache time for static resources on `custom/`, `public/` and all uploaded avatars.
265+
- `STATIC_CACHE_TIME`: **6h**: Web browser cache time for static resources on `custom/`, `public/` and all uploaded avatars. Note that this cache is disabled when `RUN_MODE` is "dev".
266266
- `ENABLE_GZIP`: **false**: Enables application-level GZIP support.
267267
- `ENABLE_PPROF`: **false**: Application profiling (memory and cpu). For "web" command it listens on localhost:6060. For "serv" command it dumps to disk at `PPROF_DATA_PATH` as `(cpuprofile|memprofile)_<username>_<temporary id>`
268268
- `PPROF_DATA_PATH`: **data/tmp/pprof**: `PPROF_DATA_PATH`, use an absolute path when you start gitea as service

docs/content/doc/installation/from-package.en-us.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,29 @@ menu:
1515

1616
# Installation from package
1717

18-
## Debian
18+
## Alpine Linux
1919

20-
Although there is a package of Gitea in Debian's [contrib](https://wiki.debian.org/SourcesList),
21-
it is not supported directly by us.
20+
Alpine Linux has [Gitea](https://pkgs.alpinelinux.org/packages?name=gitea&branch=edge) in its community repository which follows the latest stable version.
2221

23-
Unfortunately, the package is not maintained anymore and broken because of missing sources.
24-
Please follow the [deployment from binary]({{< relref "from-binary.en-us.md" >}}) guide instead.
22+
```sh
23+
apk add gitea
24+
```
2525

26-
Should the packages get updated and fixed, we will provide up-to-date installation instructions here.
26+
## Arch Linux
2727

28-
## Alpine Linux
28+
The rolling release distribution has [Gitea](https://www.archlinux.org/packages/community/x86_64/gitea/) in their official community repository and package updates are provided with new Gitea releases.
2929

30-
Alpine Linux has gitea in its community repository. It follows the latest stable version.
31-
for more information look at https://pkgs.alpinelinux.org/packages?name=gitea&branch=edge.
30+
```sh
31+
pacman -S gitea
32+
```
33+
34+
## Arch Linux ARM
35+
36+
Arch Linux ARM provides packages for [aarch64](https://archlinuxarm.org/packages/aarch64/gitea), [armv7h](https://archlinuxarm.org/packages/armv7h/gitea) and [armv6h](https://archlinuxarm.org/packages/armv6h/gitea).
3237

33-
install as usual:
3438
```sh
35-
apk add gitea
39+
pacman -S gitea
3640
```
37-
config is found in **/etc/gitea/app.ini**
3841

3942
## Windows
4043

integrations/api_admin_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,22 @@ func TestAPIListUsersNonAdmin(t *testing.T) {
144144
req := NewRequestf(t, "GET", "/api/v1/admin/users?token=%s", token)
145145
session.MakeRequest(t, req, http.StatusForbidden)
146146
}
147+
148+
func TestAPICreateUserInvalidEmail(t *testing.T) {
149+
defer prepareTestEnv(t)()
150+
adminUsername := "user1"
151+
session := loginUser(t, adminUsername)
152+
token := getTokenForLoggedInUser(t, session)
153+
urlStr := fmt.Sprintf("/api/v1/admin/users?token=%s", token)
154+
req := NewRequestWithValues(t, "POST", urlStr, map[string]string{
155+
"email": "[email protected]\r\n",
156+
"full_name": "invalid user",
157+
"login_name": "invalidUser",
158+
"must_change_password": "true",
159+
"password": "password",
160+
"send_notify": "true",
161+
"source_id": "0",
162+
"username": "invalidUser",
163+
})
164+
session.MakeRequest(t, req, http.StatusUnprocessableEntity)
165+
}

integrations/create_no_session_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func TestSessionFileCreation(t *testing.T) {
5959
defer func() {
6060
setting.SessionConfig.ProviderConfig = oldSessionConfig
6161
c = routes.NewChi()
62-
routes.RegisterRoutes(c)
62+
c.Mount("/", routes.NormalRoutes())
63+
routes.DelegateToMacaron(c)
6364
}()
6465

6566
var config session.Options
@@ -84,7 +85,8 @@ func TestSessionFileCreation(t *testing.T) {
8485
setting.SessionConfig.ProviderConfig = string(newConfigBytes)
8586

8687
c = routes.NewChi()
87-
routes.RegisterRoutes(c)
88+
c.Mount("/", routes.NormalRoutes())
89+
routes.DelegateToMacaron(c)
8890

8991
t.Run("NoSessionOnViewIssue", func(t *testing.T) {
9092
defer PrintCurrentTest(t)()

integrations/integration_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ func TestMain(m *testing.M) {
6868

6969
initIntegrationTest()
7070
c = routes.NewChi()
71-
routes.RegisterRoutes(c)
71+
c.Mount("/", routes.NormalRoutes())
72+
routes.DelegateToMacaron(c)
7273

7374
// integration test settings...
7475
if setting.Cfg != nil {

integrations/pull_merge_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func TestCantMergeWorkInProgress(t *testing.T) {
194194
req := NewRequest(t, "GET", resp.Header().Get("Location"))
195195
resp = session.MakeRequest(t, req, http.StatusOK)
196196
htmlDoc := NewHTMLParser(t, resp.Body)
197-
text := strings.TrimSpace(htmlDoc.doc.Find(".attached.merge-section.no-header > .text.grey").Last().Text())
197+
text := strings.TrimSpace(htmlDoc.doc.Find(".merge-section > .item").Last().Text())
198198
assert.NotEmpty(t, text, "Can't find WIP text")
199199

200200
// remove <strong /> from lang

integrations/pull_status_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func TestPullCreate_EmptyChangesWithCommits(t *testing.T) {
114114
resp := session.MakeRequest(t, req, http.StatusOK)
115115
doc := NewHTMLParser(t, resp.Body)
116116

117-
text := strings.TrimSpace(doc.doc.Find(".item.text.green").Text())
118-
assert.EqualValues(t, "This pull request can be merged automatically.", text)
117+
text := strings.TrimSpace(doc.doc.Find(".merge-section").Text())
118+
assert.Contains(t, text, "This pull request can be merged automatically.")
119119
})
120120
}

integrations/signup_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
package integrations
66

77
import (
8+
"fmt"
89
"net/http"
10+
"strings"
911
"testing"
1012

1113
"code.gitea.io/gitea/modules/setting"
14+
"github.com/stretchr/testify/assert"
15+
"github.com/unknwon/i18n"
1216
)
1317

1418
func TestSignup(t *testing.T) {
@@ -28,3 +32,37 @@ func TestSignup(t *testing.T) {
2832
req = NewRequest(t, "GET", "/exampleUser")
2933
MakeRequest(t, req, http.StatusOK)
3034
}
35+
36+
func TestSignupEmail(t *testing.T) {
37+
defer prepareTestEnv(t)()
38+
39+
setting.Service.EnableCaptcha = false
40+
41+
tests := []struct {
42+
email string
43+
wantStatus int
44+
wantMsg string
45+
}{
46+
{"[email protected]\r\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
47+
{"[email protected]\r", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
48+
{"[email protected]\n", http.StatusOK, i18n.Tr("en", "form.email_invalid", nil)},
49+
{"[email protected]", http.StatusFound, ""},
50+
}
51+
52+
for i, test := range tests {
53+
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
54+
"user_name": fmt.Sprintf("exampleUser%d", i),
55+
"email": test.email,
56+
"password": "examplePassword!1",
57+
"retype": "examplePassword!1",
58+
})
59+
resp := MakeRequest(t, req, test.wantStatus)
60+
if test.wantMsg != "" {
61+
htmlDoc := NewHTMLParser(t, resp.Body)
62+
assert.Equal(t,
63+
test.wantMsg,
64+
strings.TrimSpace(htmlDoc.doc.Find(".ui.message").Text()),
65+
)
66+
}
67+
}
68+
}

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os"
1212
"runtime"
1313
"strings"
14+
"time"
1415

1516
"code.gitea.io/gitea/cmd"
1617
"code.gitea.io/gitea/modules/log"
@@ -40,6 +41,7 @@ var (
4041
func init() {
4142
setting.AppVer = Version
4243
setting.AppBuiltWith = formatBuiltWith()
44+
setting.AppStartTime = time.Now().UTC()
4345

4446
// Grab the original help templates
4547
originalAppHelpTemplate = cli.AppHelpTemplate

models/error.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,21 @@ func (err ErrEmailAlreadyUsed) Error() string {
193193
return fmt.Sprintf("e-mail already in use [email: %s]", err.Email)
194194
}
195195

196+
// ErrEmailInvalid represents an error where the email address does not comply with RFC 5322
197+
type ErrEmailInvalid struct {
198+
Email string
199+
}
200+
201+
// IsErrEmailInvalid checks if an error is an ErrEmailInvalid
202+
func IsErrEmailInvalid(err error) bool {
203+
_, ok := err.(ErrEmailInvalid)
204+
return ok
205+
}
206+
207+
func (err ErrEmailInvalid) Error() string {
208+
return fmt.Sprintf("e-mail invalid [email: %s]", err.Email)
209+
}
210+
196211
// ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
197212
type ErrOpenIDAlreadyUsed struct {
198213
OpenID string

models/user.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"errors"
1515
"fmt"
1616
_ "image/jpeg" // Needed for jpeg support
17+
"net/mail"
1718
"os"
1819
"path/filepath"
1920
"regexp"
@@ -808,6 +809,11 @@ func CreateUser(u *User) (err error) {
808809
return ErrEmailAlreadyUsed{u.Email}
809810
}
810811

812+
_, err = mail.ParseAddress(u.Email)
813+
if err != nil {
814+
return ErrEmailInvalid{u.Email}
815+
}
816+
811817
isExist, err = isEmailUsed(sess, u.Email)
812818
if err != nil {
813819
return err
@@ -951,7 +957,12 @@ func checkDupEmail(e Engine, u *User) error {
951957
}
952958

953959
func updateUser(e Engine, u *User) error {
954-
_, err := e.ID(u.ID).AllCols().Update(u)
960+
u.Email = strings.ToLower(u.Email)
961+
_, err := mail.ParseAddress(u.Email)
962+
if err != nil {
963+
return ErrEmailInvalid{u.Email}
964+
}
965+
_, err = e.ID(u.ID).AllCols().Update(u)
955966
return err
956967
}
957968

models/user_mail.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package models
88
import (
99
"errors"
1010
"fmt"
11+
"net/mail"
1112
"strings"
1213

1314
"code.gitea.io/gitea/modules/log"
@@ -143,6 +144,11 @@ func addEmailAddress(e Engine, email *EmailAddress) error {
143144
return ErrEmailAlreadyUsed{email.Email}
144145
}
145146

147+
_, err = mail.ParseAddress(email.Email)
148+
if err != nil {
149+
return ErrEmailInvalid{email.Email}
150+
}
151+
146152
_, err = e.Insert(email)
147153
return err
148154
}
@@ -167,6 +173,10 @@ func AddEmailAddresses(emails []*EmailAddress) error {
167173
} else if used {
168174
return ErrEmailAlreadyUsed{emails[i].Email}
169175
}
176+
_, err = mail.ParseAddress(emails[i].Email)
177+
if err != nil {
178+
return ErrEmailInvalid{emails[i].Email}
179+
}
170180
}
171181

172182
if _, err := x.Insert(emails); err != nil {

models/user_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,21 @@ func TestCreateUser(t *testing.T) {
329329
assert.NoError(t, DeleteUser(user))
330330
}
331331

332+
func TestCreateUserInvalidEmail(t *testing.T) {
333+
user := &User{
334+
Name: "GiteaBot",
335+
Email: "[email protected]\r\n",
336+
Passwd: ";p['////..-++']",
337+
IsAdmin: false,
338+
Theme: setting.UI.DefaultTheme,
339+
MustChangePassword: false,
340+
}
341+
342+
err := CreateUser(user)
343+
assert.Error(t, err)
344+
assert.True(t, IsErrEmailInvalid(err))
345+
}
346+
332347
func TestCreateUser_Issue5882(t *testing.T) {
333348

334349
// Init settings

0 commit comments

Comments
 (0)