Skip to content

Commit 7d2c0fd

Browse files
committed
Merge branch 'release/v1.10' of git://github.com/go-gitea/gitea into wild/v1.10
2 parents c3bc947 + fbcf235 commit 7d2c0fd

File tree

10 files changed

+105
-65
lines changed

10 files changed

+105
-65
lines changed

integrations/signup_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ func TestSignup(t *testing.T) {
1919
req := NewRequestWithValues(t, "POST", "/user/sign_up", map[string]string{
2020
"user_name": "exampleUser",
2121
"email": "[email protected]",
22-
"password": "examplePassword",
23-
"retype": "examplePassword",
22+
"password": "examplePassword!1",
23+
"retype": "examplePassword!1",
2424
})
2525
MakeRequest(t, req, http.StatusFound)
2626

models/ssh_key.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func parseKeyString(content string) (string, error) {
107107

108108
var keyType, keyContent, keyComment string
109109

110-
if content[:len(ssh2keyStart)] == ssh2keyStart {
110+
if strings.HasPrefix(content, ssh2keyStart) {
111111
// Parse SSH2 file format.
112112

113113
// Transform all legal line endings to a single "\n".

models/ssh_key_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ AAAAC3NzaC1lZDI1NTE5AAAAICV0MGX/W9IvLA4FXpIuUcdDcbj5KX4syHgsTy7soVgf
131131
_, err := CheckPublicKeyString(test.content)
132132
assert.NoError(t, err)
133133
}
134+
135+
for _, invalidKeys := range []struct {
136+
content string
137+
}{
138+
{"test"},
139+
{"---- NOT A REAL KEY ----"},
140+
{"bad\nkey"},
141+
{"\t\t:)\t\r\n"},
142+
{"\r\ntest \r\ngitea\r\n\r\n"},
143+
} {
144+
_, err := CheckPublicKeyString(invalidKeys.content)
145+
assert.Error(t, err)
146+
}
134147
}
135148

136149
func Test_calcFingerprint(t *testing.T) {

modules/migrations/gitea.go

+39-33
Original file line numberDiff line numberDiff line change
@@ -252,27 +252,30 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
252252
}
253253

254254
// download attachment
255-
resp, err := http.Get(asset.URL)
256-
if err != nil {
257-
return err
258-
}
259-
defer resp.Body.Close()
255+
err = func() error {
256+
resp, err := http.Get(asset.URL)
257+
if err != nil {
258+
return err
259+
}
260+
defer resp.Body.Close()
260261

261-
localPath := attach.LocalPath()
262-
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
263-
return fmt.Errorf("MkdirAll: %v", err)
264-
}
262+
localPath := attach.LocalPath()
263+
if err = os.MkdirAll(path.Dir(localPath), os.ModePerm); err != nil {
264+
return fmt.Errorf("MkdirAll: %v", err)
265+
}
265266

266-
fw, err := os.Create(localPath)
267-
if err != nil {
268-
return fmt.Errorf("Create: %v", err)
269-
}
270-
defer fw.Close()
267+
fw, err := os.Create(localPath)
268+
if err != nil {
269+
return fmt.Errorf("Create: %v", err)
270+
}
271+
defer fw.Close()
271272

272-
if _, err := io.Copy(fw, resp.Body); err != nil {
273+
_, err = io.Copy(fw, resp.Body)
274+
return err
275+
}()
276+
if err != nil {
273277
return err
274278
}
275-
276279
rel.Attachments = append(rel.Attachments, &attach)
277280
}
278281

@@ -468,21 +471,24 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
468471
}
469472

470473
// download patch file
471-
resp, err := http.Get(pr.PatchURL)
472-
if err != nil {
473-
return nil, err
474-
}
475-
defer resp.Body.Close()
476-
pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
477-
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil {
478-
return nil, err
479-
}
480-
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number)))
481-
if err != nil {
482-
return nil, err
483-
}
484-
defer f.Close()
485-
_, err = io.Copy(f, resp.Body)
474+
err := func() error {
475+
resp, err := http.Get(pr.PatchURL)
476+
if err != nil {
477+
return err
478+
}
479+
defer resp.Body.Close()
480+
pullDir := filepath.Join(g.repo.RepoPath(), "pulls")
481+
if err = os.MkdirAll(pullDir, os.ModePerm); err != nil {
482+
return err
483+
}
484+
f, err := os.Create(filepath.Join(pullDir, fmt.Sprintf("%d.patch", pr.Number)))
485+
if err != nil {
486+
return err
487+
}
488+
defer f.Close()
489+
_, err = io.Copy(f, resp.Body)
490+
return err
491+
}()
486492
if err != nil {
487493
return nil, err
488494
}
@@ -496,8 +502,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
496502
if err != nil {
497503
return nil, err
498504
}
499-
defer p.Close()
500505
_, err = p.WriteString(pr.Head.SHA)
506+
p.Close()
501507
if err != nil {
502508
return nil, err
503509
}
@@ -531,8 +537,8 @@ func (g *GiteaLocalUploader) newPullRequest(pr *base.PullRequest) (*models.PullR
531537
if err != nil {
532538
return nil, err
533539
}
534-
defer b.Close()
535540
_, err = b.WriteString(pr.Head.SHA)
541+
b.Close()
536542
if err != nil {
537543
return nil, err
538544
}

modules/templates/helper.go

+27-14
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"runtime"
2020
"strings"
2121
"time"
22+
"unicode"
2223

2324
"code.gitea.io/gitea/models"
2425
"code.gitea.io/gitea/modules/base"
@@ -331,34 +332,46 @@ func RenderCommitMessageLink(msg, urlPrefix, urlDefault string, metas map[string
331332
// RenderCommitMessageLinkSubject renders commit message as a XXS-safe link to
332333
// the provided default url, handling for special links without email to links.
333334
func RenderCommitMessageLinkSubject(msg, urlPrefix, urlDefault string, metas map[string]string) template.HTML {
334-
cleanMsg := template.HTMLEscapeString(msg)
335+
msgLine := strings.TrimLeftFunc(msg, unicode.IsSpace)
336+
lineEnd := strings.IndexByte(msgLine, '\n')
337+
if lineEnd > 0 {
338+
msgLine = msgLine[:lineEnd]
339+
}
340+
msgLine = strings.TrimRightFunc(msgLine, unicode.IsSpace)
341+
if len(msgLine) == 0 {
342+
return template.HTML("")
343+
}
344+
335345
// we can safely assume that it will not return any error, since there
336346
// shouldn't be any special HTML.
337-
fullMessage, err := markup.RenderCommitMessageSubject([]byte(cleanMsg), urlPrefix, urlDefault, metas)
347+
renderedMessage, err := markup.RenderCommitMessageSubject([]byte(template.HTMLEscapeString(msgLine)), urlPrefix, urlDefault, metas)
338348
if err != nil {
339349
log.Error("RenderCommitMessageSubject: %v", err)
340-
return ""
341-
}
342-
msgLines := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
343-
if len(msgLines) == 0 {
344350
return template.HTML("")
345351
}
346-
return template.HTML(msgLines[0])
352+
return template.HTML(renderedMessage)
347353
}
348354

349355
// RenderCommitBody extracts the body of a commit message without its title.
350356
func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.HTML {
351-
cleanMsg := template.HTMLEscapeString(msg)
352-
fullMessage, err := markup.RenderCommitMessage([]byte(cleanMsg), urlPrefix, "", metas)
357+
msgLine := strings.TrimRightFunc(msg, unicode.IsSpace)
358+
lineEnd := strings.IndexByte(msgLine, '\n')
359+
if lineEnd > 0 {
360+
msgLine = msgLine[lineEnd+1:]
361+
} else {
362+
return template.HTML("")
363+
}
364+
msgLine = strings.TrimLeftFunc(msgLine, unicode.IsSpace)
365+
if len(msgLine) == 0 {
366+
return template.HTML("")
367+
}
368+
369+
renderedMessage, err := markup.RenderCommitMessage([]byte(template.HTMLEscapeString(msgLine)), urlPrefix, "", metas)
353370
if err != nil {
354371
log.Error("RenderCommitMessage: %v", err)
355372
return ""
356373
}
357-
body := strings.Split(strings.TrimSpace(string(fullMessage)), "\n")
358-
if len(body) == 0 {
359-
return template.HTML("")
360-
}
361-
return template.HTML(strings.Join(body[1:], "\n"))
374+
return template.HTML(renderedMessage)
362375
}
363376

364377
// RenderNote renders the contents of a git-notes file as a commit message.

public/js/index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2875,7 +2875,8 @@ function initFilterBranchTagDropdown(selector) {
28752875
});
28762876
}
28772877

2878-
$(".commit-button").click(function() {
2878+
$(".commit-button").click(function(e) {
2879+
e.preventDefault();
28792880
$(this).parent().find('.commit-body').toggle();
28802881
});
28812882

routers/admin/users.go

+11-9
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,11 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
7979
}
8080

8181
u := &models.User{
82-
Name: form.UserName,
83-
Email: form.Email,
84-
Passwd: form.Password,
85-
IsActive: true,
86-
LoginType: models.LoginPlain,
87-
MustChangePassword: form.MustChangePassword,
82+
Name: form.UserName,
83+
Email: form.Email,
84+
Passwd: form.Password,
85+
IsActive: true,
86+
LoginType: models.LoginPlain,
8887
}
8988

9089
if len(form.LoginType) > 0 {
@@ -95,9 +94,12 @@ func NewUserPost(ctx *context.Context, form auth.AdminCreateUserForm) {
9594
u.LoginName = form.LoginName
9695
}
9796
}
98-
if !password.IsComplexEnough(form.Password) {
99-
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
100-
return
97+
if u.LoginType == models.LoginPlain {
98+
if !password.IsComplexEnough(form.Password) {
99+
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplUserNew, &form)
100+
return
101+
}
102+
u.MustChangePassword = form.MustChangePassword
101103
}
102104
if err := models.CreateUser(u); err != nil {
103105
switch {

routers/user/auth.go

+8-3
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ func oAuth2UserLoginCallback(loginSource *models.LoginSource, request *http.Requ
707707

708708
// LinkAccount shows the page where the user can decide to login or create a new account
709709
func LinkAccount(ctx *context.Context) {
710-
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationCaptcha || setting.Service.AllowOnlyExternalRegistration
710+
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
711711
ctx.Data["Title"] = ctx.Tr("link_account")
712712
ctx.Data["LinkAccountMode"] = true
713713
ctx.Data["EnableCaptcha"] = setting.Service.EnableCaptcha && setting.Service.RequireExternalRegistrationCaptcha
@@ -757,7 +757,7 @@ func LinkAccount(ctx *context.Context) {
757757

758758
// LinkAccountPostSignIn handle the coupling of external account with another account using signIn
759759
func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
760-
ctx.Data["DisablePassword"] = setting.Service.AllowOnlyExternalRegistration
760+
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
761761
ctx.Data["Title"] = ctx.Tr("link_account")
762762
ctx.Data["LinkAccountMode"] = true
763763
ctx.Data["LinkAccountModeSignIn"] = true
@@ -840,7 +840,7 @@ func LinkAccountPostSignIn(ctx *context.Context, signInForm auth.SignInForm) {
840840
func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterForm) {
841841
// TODO Make insecure passwords optional for local accounts also,
842842
// once email-based Second-Factor Auth is available
843-
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationCaptcha || setting.Service.AllowOnlyExternalRegistration
843+
ctx.Data["DisablePassword"] = !setting.Service.RequireExternalRegistrationPassword || setting.Service.AllowOnlyExternalRegistration
844844
ctx.Data["Title"] = ctx.Tr("link_account")
845845
ctx.Data["LinkAccountMode"] = true
846846
ctx.Data["LinkAccountModeRegister"] = true
@@ -1070,6 +1070,11 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo
10701070
ctx.RenderWithErr(ctx.Tr("auth.password_too_short", setting.MinPasswordLength), tplSignUp, &form)
10711071
return
10721072
}
1073+
if !password.IsComplexEnough(form.Password) {
1074+
ctx.Data["Err_Password"] = true
1075+
ctx.RenderWithErr(ctx.Tr("form.password_complexity"), tplSignUp, &form)
1076+
return
1077+
}
10731078

10741079
u := &models.User{
10751080
Name: form.UserName,

templates/admin/user/new.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
<input id="password" name="password" type="password" value="{{.password}}" {{if eq .login_type "0-0"}}required{{end}}>
4343
</div>
4444

45-
<div class="inline field">
45+
<div class="inline field local{{if ne .login_type "0-0"}} hide{{end}}">
4646
<div class="ui checkbox">
4747
<label><strong>{{.i18n.Tr "auth.allow_password_change" }}</strong></label>
4848
<input name="must_change_password" type="checkbox" checked>

templates/repo/issue/view_content.tmpl

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<div class="content">
2323
<div class="ui top attached header">
2424
{{if .Issue.OriginalAuthor }}
25-
<span class="text black"><i class="fa {{MigrationIcon .Repository.GetOriginalURLHostname}}" aria-hidden="true"></i> {{ .Issue.OriginalAuthor }}</span><span class="text grey"> {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}}<span> <span class="text migrate">{{if .Repository.OriginalURL}} ({{$.i18n.Tr "repo.migrated_from" .Repository.OriginalURL .Repository.GetOriginalURLHostname | Safe }}){{end}}</span>
25+
<span class="text black"><i class="fa {{MigrationIcon .Repository.GetOriginalURLHostname}}" aria-hidden="true"></i> {{ .Issue.OriginalAuthor }}</span><span class="text grey"> {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}}</span> <span class="text migrate">{{if .Repository.OriginalURL}} ({{$.i18n.Tr "repo.migrated_from" .Repository.OriginalURL .Repository.GetOriginalURLHostname | Safe }}){{end}}</span>
2626
{{else}}
2727
<span class="text grey"><a {{if gt .Issue.Poster.ID 0}}href="{{.Issue.Poster.HomeLink}}"{{end}}>{{.Issue.Poster.GetDisplayName}}</a> {{.i18n.Tr "repo.issues.commented_at" .Issue.HashTag $createdStr | Safe}}</span>
2828
{{end}}

0 commit comments

Comments
 (0)