Skip to content

Commit 93bd290

Browse files
authored
Merge branch 'go-gitea:main' into fix/markdown-dark-light-mode
2 parents 2520f40 + 068d7a5 commit 93bd290

File tree

12 files changed

+67
-52
lines changed

12 files changed

+67
-52
lines changed

contrib/upgrade.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ curl --connect-timeout 10 --silent --show-error --fail --location -O "$binurl{,.
108108
sha256sum -c "${binname}.xz.sha256"
109109
if [[ -z "${ignore_gpg:-}" ]]; then
110110
require gpg
111-
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
111+
# try to use curl first, it uses standard tcp 443 port and works better behind strict firewall rules
112+
curl -fsSL --connect-timeout 10 "https://keys.openpgp.org/vks/v1/by-fingerprint/7C9E68152594688862D62AF62D9AE806EC1592E2" | gpg --import \
113+
|| gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
112114
gpg --verify "${binname}.xz.asc" "${binname}.xz" || { echo 'Signature does not match'; exit 1; }
113115
fi
114116
rm "${binname}".xz.{sha256,asc}
@@ -127,6 +129,8 @@ echo "Creating backup in $giteahome"
127129
giteacmd dump $backupopts
128130
echo "Updating binary at $giteabin"
129131
cp -f "$giteabin" "$giteabin.bak" && mv -f "$binname" "$giteabin"
132+
# Restore SELinux context if applicable (e.g. RHEL/Fedora)
133+
command -v restorecon &>/dev/null && restorecon -v "$giteabin" || true
130134
$service_start
131135
$service_status
132136

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ require (
3737
github.com/charmbracelet/git-lfs-transfer v0.1.1-0.20251013092601-6327009efd21
3838
github.com/chi-middleware/proxy v1.1.1
3939
github.com/dimiro1/reply v0.0.0-20200315094148-d0136a4c9e21
40+
github.com/dlclark/regexp2 v1.11.5
4041
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707
4142
github.com/dustin/go-humanize v1.0.1
4243
github.com/editorconfig/editorconfig-core-go/v2 v2.6.4
@@ -183,7 +184,6 @@ require (
183184
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
184185
github.com/davidmz/go-pageant v1.0.2 // indirect
185186
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
186-
github.com/dlclark/regexp2 v1.11.5 // indirect
187187
github.com/emersion/go-sasl v0.0.0-20241020182733-b788ff22d5a6 // indirect
188188
github.com/fatih/color v1.18.0 // indirect
189189
github.com/fxamacker/cbor/v2 v2.9.0 // indirect

models/issues/pull.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"errors"
1010
"fmt"
1111
"io"
12-
"regexp"
1312
"strings"
1413

1514
"code.gitea.io/gitea/models/db"
@@ -24,6 +23,7 @@ import (
2423
"code.gitea.io/gitea/modules/timeutil"
2524
"code.gitea.io/gitea/modules/util"
2625

26+
"github.com/dlclark/regexp2"
2727
"xorm.io/builder"
2828
)
2929

@@ -861,7 +861,7 @@ func GetCodeOwnersFromContent(ctx context.Context, data string) ([]*CodeOwnerRul
861861
}
862862

863863
type CodeOwnerRule struct {
864-
Rule *regexp.Regexp
864+
Rule *regexp2.Regexp // it supports negative lookahead, does better for end users
865865
Negative bool
866866
Users []*user_model.User
867867
Teams []*org_model.Team
@@ -877,7 +877,8 @@ func ParseCodeOwnersLine(ctx context.Context, tokens []string) (*CodeOwnerRule,
877877

878878
warnings := make([]string, 0)
879879

880-
rule.Rule, err = regexp.Compile(fmt.Sprintf("^%s$", strings.TrimPrefix(tokens[0], "!")))
880+
expr := fmt.Sprintf("^%s$", strings.TrimPrefix(tokens[0], "!"))
881+
rule.Rule, err = regexp2.Compile(expr, regexp2.None)
881882
if err != nil {
882883
warnings = append(warnings, fmt.Sprintf("incorrect codeowner regexp: %s", err))
883884
return nil, warnings

models/migrations/base/db.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
402402
cols += "DROP COLUMN `" + col + "` CASCADE"
403403
}
404404
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
405-
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
405+
return fmt.Errorf("drop table `%s` columns %v: %w", tableName, columnNames, err)
406406
}
407407
case setting.Database.Type.IsMySQL():
408408
// Drop indexes on columns first
@@ -430,7 +430,7 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
430430
cols += "DROP COLUMN `" + col + "`"
431431
}
432432
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` %s", tableName, cols)); err != nil {
433-
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
433+
return fmt.Errorf("drop table `%s` columns %v: %w", tableName, columnNames, err)
434434
}
435435
case setting.Database.Type.IsMSSQL():
436436
cols := ""
@@ -444,27 +444,27 @@ func DropTableColumns(sess *xorm.Session, tableName string, columnNames ...strin
444444
tableName, strings.ReplaceAll(cols, "`", "'"))
445445
constraints := make([]string, 0)
446446
if err := sess.SQL(sql).Find(&constraints); err != nil {
447-
return fmt.Errorf("Find constraints: %v", err)
447+
return fmt.Errorf("find constraints: %w", err)
448448
}
449449
for _, constraint := range constraints {
450450
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP CONSTRAINT `%s`", tableName, constraint)); err != nil {
451-
return fmt.Errorf("Drop table `%s` default constraint `%s`: %v", tableName, constraint, err)
451+
return fmt.Errorf("drop table `%s` default constraint `%s`: %w", tableName, constraint, err)
452452
}
453453
}
454454
sql = fmt.Sprintf("SELECT DISTINCT Name FROM sys.indexes INNER JOIN sys.index_columns ON indexes.index_id = index_columns.index_id AND indexes.object_id = index_columns.object_id WHERE indexes.object_id = OBJECT_ID('%[1]s') AND index_columns.column_id IN (SELECT column_id FROM sys.columns WHERE LOWER(name) IN (%[2]s) AND object_id = OBJECT_ID('%[1]s'))",
455455
tableName, strings.ReplaceAll(cols, "`", "'"))
456456
constraints = make([]string, 0)
457457
if err := sess.SQL(sql).Find(&constraints); err != nil {
458-
return fmt.Errorf("Find constraints: %v", err)
458+
return fmt.Errorf("find constraints: %w", err)
459459
}
460460
for _, constraint := range constraints {
461461
if _, err := sess.Exec(fmt.Sprintf("DROP INDEX `%[2]s` ON `%[1]s`", tableName, constraint)); err != nil {
462-
return fmt.Errorf("Drop index `%[2]s` on `%[1]s`: %v", tableName, constraint, err)
462+
return fmt.Errorf("drop index `%[2]s` on `%[1]s`: %[3]w", tableName, constraint, err)
463463
}
464464
}
465465

466466
if _, err := sess.Exec(fmt.Sprintf("ALTER TABLE `%s` DROP COLUMN %s", tableName, cols)); err != nil {
467-
return fmt.Errorf("Drop table `%s` columns %v: %v", tableName, columnNames, err)
467+
return fmt.Errorf("drop table `%s` columns %v: %w", tableName, columnNames, err)
468468
}
469469
default:
470470
log.Fatal("Unrecognized DB")

modules/markup/common/linkify.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
9696
m[1] -= closing
9797
}
9898
} else if lastChar == ';' {
99+
// exclude HTML entity reference, e.g.: exclude " " from "http://example.com?foo=1 "
99100
i := m[1] - 2
100101
for ; i >= m[0]; i-- {
101102
if util.IsAlphaNumeric(line[i]) {
@@ -105,7 +106,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
105106
}
106107
if i != m[1]-2 {
107108
if line[i] == '&' {
108-
m[1] -= m[1] - i
109+
m[1] = i
109110
}
110111
}
111112
}

options/locale/locale_ga-IE.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,6 +3644,7 @@
36443644
"actions.runners.id": "ID",
36453645
"actions.runners.name": "Ainm",
36463646
"actions.runners.owner_type": "Cineál",
3647+
"actions.runners.availability": "Infhaighteacht",
36473648
"actions.runners.description": "Cur síos",
36483649
"actions.runners.labels": "Lipéid",
36493650
"actions.runners.last_online": "Am Ar Líne Deiridh",
@@ -3659,6 +3660,12 @@
36593660
"actions.runners.update_runner": "Nuashonrú Athruithe",
36603661
"actions.runners.update_runner_success": "Nuashonraíodh an Reathaí",
36613662
"actions.runners.update_runner_failed": "Theip ar an reathaí a nuashonrú",
3663+
"actions.runners.enable_runner": "Cumasaigh an ritheoir seo",
3664+
"actions.runners.enable_runner_success": "Cumasaíodh an rithire go rathúil",
3665+
"actions.runners.enable_runner_failed": "Theip ar an rithire a chumasú",
3666+
"actions.runners.disable_runner": "Díchumasaigh an ritheoir seo",
3667+
"actions.runners.disable_runner_success": "Díchumasaíodh an ritheoir go rathúil",
3668+
"actions.runners.disable_runner_failed": "Theip ar an ritheoir a dhíchumasú",
36623669
"actions.runners.delete_runner": "Scrios an reathaí seo",
36633670
"actions.runners.delete_runner_success": "Scriosadh an reathaí go rathúil",
36643671
"actions.runners.delete_runner_failed": "Theip ar an reathaí a scriosadh",

routers/api/packages/api.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ func reqPackageAccess(accessMode perm.AccessMode) func(ctx *context.Context) {
8888
}
8989
}
9090

91-
func verifyAuth(r *web.Router, authMethods []auth.Method) {
91+
type verifyAuthOptions struct {
92+
afterAuthCallback func(ctx *context.Context, err error)
93+
}
94+
95+
func verifyAuth(r *web.Router, authMethods []auth.Method, opts verifyAuthOptions) {
9296
if setting.Service.EnableReverseProxyAuth {
9397
authMethods = append(authMethods, &auth.ReverseProxy{})
9498
}
@@ -97,12 +101,13 @@ func verifyAuth(r *web.Router, authMethods []auth.Method) {
97101
r.AfterRouting(func(ctx *context.Context) {
98102
var err error
99103
ctx.Doer, err = authGroup.Verify(ctx.Req, ctx.Resp, ctx, ctx.Session)
100-
if err != nil {
104+
ctx.IsSigned = ctx.Doer != nil
105+
if opts.afterAuthCallback != nil {
106+
opts.afterAuthCallback(ctx, err)
107+
} else if err != nil {
101108
log.Error("Failed to verify user: %v", err)
102109
ctx.HTTPError(http.StatusUnauthorized, "Failed to authenticate user")
103-
return
104110
}
105-
ctx.IsSigned = ctx.Doer != nil
106111
})
107112
}
108113

@@ -119,7 +124,7 @@ func CommonRoutes() *web.Router {
119124
&nuget.Auth{},
120125
&Auth{},
121126
&chef.Auth{},
122-
})
127+
}, verifyAuthOptions{})
123128

124129
r.Group("/{username}", func() {
125130
r.Group("/alpine", func() {
@@ -537,8 +542,15 @@ func ContainerRoutes() *web.Router {
537542

538543
verifyAuth(r, []auth.Method{
539544
&auth.Basic{},
540-
// container auth requires an token, so container.Authenticate issues a Ghost user token for anonymous access
545+
// container auth requires token, so container.Authenticate issues a Ghost user token for anonymous access
541546
&Auth{AllowGhostUser: true},
547+
}, verifyAuthOptions{
548+
afterAuthCallback: func(ctx *context.Context, err error) {
549+
if err != nil {
550+
log.Error("Failed to verify container user: %v", err)
551+
container.APIUnauthorizedError(ctx)
552+
}
553+
},
542554
})
543555

544556
// TODO: Content Discovery / References (not implemented yet)

routers/api/packages/container/container.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,17 +120,19 @@ func apiErrorDefined(ctx *context.Context, err *namedError) {
120120
})
121121
}
122122

123-
func apiUnauthorizedError(ctx *context.Context) {
123+
func APIUnauthorizedError(ctx *context.Context) {
124124
// container registry requires that the "/v2" must be in the root, so the sub-path in AppURL should be removed
125125
realmURL := httplib.GuessCurrentHostURL(ctx) + "/v2/token"
126126
ctx.Resp.Header().Add("WWW-Authenticate", `Bearer realm="`+realmURL+`",service="container_registry",scope="*"`)
127+
// support apple container like: container registry login <gitea-host> -u
128+
ctx.Resp.Header().Add("WWW-Authenticate", `Basic realm="Gitea Container Registry"`)
127129
apiErrorDefined(ctx, errUnauthorized)
128130
}
129131

130132
// ReqContainerAccess is a middleware which checks the current user valid (real user or ghost if anonymous access is enabled)
131133
func ReqContainerAccess(ctx *context.Context) {
132134
if ctx.Doer == nil || (setting.Service.RequireSignInViewStrict && ctx.Doer.IsGhost()) {
133-
apiUnauthorizedError(ctx)
135+
APIUnauthorizedError(ctx)
134136
}
135137
}
136138

@@ -156,7 +158,7 @@ func Authenticate(ctx *context.Context) {
156158
packageScope := auth_service.GetAccessScope(ctx.Data)
157159
if u == nil {
158160
if setting.Service.RequireSignInViewStrict {
159-
apiUnauthorizedError(ctx)
161+
APIUnauthorizedError(ctx)
160162
return
161163
}
162164

@@ -170,7 +172,7 @@ func Authenticate(ctx *context.Context) {
170172
if err != nil {
171173
log.Error("Error checking access scope: %v", err)
172174
}
173-
apiUnauthorizedError(ctx)
175+
APIUnauthorizedError(ctx)
174176
return
175177
}
176178
}

routers/web/auth/oauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func SignInOAuthCallback(ctx *context.Context) {
118118
return
119119
}
120120
if err, ok := err.(*go_oauth2.RetrieveError); ok {
121-
ctx.Flash.Error("OAuth2 RetrieveError: "+err.Error(), true)
121+
ctx.Flash.Error("OAuth2 RetrieveError: " + err.Error())
122122
ctx.Redirect(setting.AppSubURL + "/user/login")
123123
return
124124
}

services/issue/pull.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ func PullRequestCodeOwnersReview(ctx context.Context, pr *issues_model.PullReque
9595
uniqTeams := make(map[string]*org_model.Team)
9696
for _, rule := range rules {
9797
for _, f := range changedFiles {
98-
if (rule.Rule.MatchString(f) && !rule.Negative) || (!rule.Rule.MatchString(f) && rule.Negative) {
98+
shouldMatch := !rule.Negative
99+
matched, _ := rule.Rule.MatchString(f) // err only happens when timeouts, any error can be considered as not matched
100+
if matched == shouldMatch {
99101
for _, u := range rule.Users {
100102
uniqUsers[u.ID] = u
101103
}

0 commit comments

Comments
 (0)