diff --git a/cmd/web.go b/cmd/web.go
index 3fc64f7748..787411939c 100644
--- a/cmd/web.go
+++ b/cmd/web.go
@@ -195,7 +195,7 @@ func serveInstalled(ctx *cli.Context) error {
publicFilesSet.Remove(".well-known")
publicFilesSet.Remove("assets")
publicFilesSet.Remove("robots.txt")
- for _, fn := range publicFilesSet.Values() {
+ for fn := range publicFilesSet.Seq() {
log.Error("Found legacy public asset %q in CustomPath. Please move it to %s/public/assets/%s", fn, setting.CustomPath, fn)
}
if _, err := os.Stat(filepath.Join(setting.CustomPath, "robots.txt")); err == nil {
diff --git a/models/user/user_test.go b/models/user/user_test.go
index df0c3856e9..2c8c1609fd 100644
--- a/models/user/user_test.go
+++ b/models/user/user_test.go
@@ -715,7 +715,7 @@ func TestDisabledUserFeatures(t *testing.T) {
// no features should be disabled with a plain login type
assert.LessOrEqual(t, user.LoginType, auth.Plain)
assert.Empty(t, user_model.DisabledFeaturesWithLoginType(user).Values())
- for _, f := range testValues.Values() {
+ for f := range testValues.Seq() {
assert.False(t, user_model.IsFeatureDisabledWithLoginType(user, f))
}
@@ -724,7 +724,7 @@ func TestDisabledUserFeatures(t *testing.T) {
// all features should be disabled
assert.NotEmpty(t, user_model.DisabledFeaturesWithLoginType(user).Values())
- for _, f := range testValues.Values() {
+ for f := range testValues.Seq() {
assert.True(t, user_model.IsFeatureDisabledWithLoginType(user, f))
}
}
diff --git a/modules/assetfs/layered.go b/modules/assetfs/layered.go
index 9678d23ad6..9feabc3f8c 100644
--- a/modules/assetfs/layered.go
+++ b/modules/assetfs/layered.go
@@ -11,7 +11,7 @@ import (
"net/http"
"os"
"path/filepath"
- "sort"
+ "slices"
"time"
"code.gitea.io/gitea/modules/container"
@@ -143,8 +143,7 @@ func (l *LayeredFS) ListFiles(name string, fileMode ...bool) ([]string, error) {
}
}
}
- files := fileSet.Values()
- sort.Strings(files)
+ files := slices.Sorted(fileSet.Seq())
return files, nil
}
@@ -184,8 +183,7 @@ func listAllFiles(layers []*Layer, name string, fileMode ...bool) ([]string, err
if err := list(name); err != nil {
return nil, err
}
- files := fileSet.Values()
- sort.Strings(files)
+ files := slices.Sorted(fileSet.Seq())
return files, nil
}
diff --git a/modules/container/set.go b/modules/container/set.go
index 2d654d0aee..70f837bc66 100644
--- a/modules/container/set.go
+++ b/modules/container/set.go
@@ -3,6 +3,11 @@
package container
+import (
+ "iter"
+ "maps"
+)
+
type Set[T comparable] map[T]struct{}
// SetOf creates a set and adds the specified elements to it.
@@ -63,3 +68,9 @@ func (s Set[T]) Values() []T {
}
return keys
}
+
+// Seq returns a iterator over the elements in the set.
+// It returns a single-use iterator.
+func (s Set[T]) Seq() iter.Seq[T] {
+ return maps.Keys(s)
+}
diff --git a/modules/container/set_test.go b/modules/container/set_test.go
index 3cfbf7cc2c..e54e31a052 100644
--- a/modules/container/set_test.go
+++ b/modules/container/set_test.go
@@ -4,6 +4,7 @@
package container
import (
+ "slices"
"testing"
"github.com/stretchr/testify/assert"
@@ -29,6 +30,14 @@ func TestSet(t *testing.T) {
assert.True(t, s.Contains("key4"))
assert.True(t, s.Contains("key5"))
+ values := s.Values()
+ called := 0
+ for value := range s.Seq() {
+ called++
+ assert.True(t, slices.Contains(values, value))
+ }
+ assert.EqualValues(t, len(values), called)
+
s = SetOf("key6", "key7")
assert.False(t, s.Contains("key1"))
assert.True(t, s.Contains("key6"))
diff --git a/modules/markup/file_preview.go b/modules/markup/file_preview.go
index 49a5f1e8ba..3caf08f7bb 100644
--- a/modules/markup/file_preview.go
+++ b/modules/markup/file_preview.go
@@ -77,6 +77,12 @@ func newFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
commitSha := node.Data[m[4]:m[5]]
filePath := node.Data[m[6]:m[7]]
+ urlFullSource := urlFull
+ if strings.HasSuffix(filePath, "?display=source") {
+ filePath = strings.TrimSuffix(filePath, "?display=source")
+ } else if Type(filePath) != "" {
+ urlFullSource = node.Data[m[0]:m[6]] + filePath + "?display=source#" + node.Data[m[8]:m[1]]
+ }
hash := node.Data[m[8]:m[9]]
preview.start = m[0]
@@ -113,7 +119,7 @@ func newFilePreview(ctx *RenderContext, node *html.Node, locale translation.Loca
titleBuffer.WriteString(" – ")
}
- err = html.Render(titleBuffer, createLink(urlFull, filePath, "muted"))
+ err = html.Render(titleBuffer, createLink(urlFullSource, filePath, "muted"))
if err != nil {
log.Error("failed to render filepathLink: %v", err)
}
diff --git a/modules/markup/html_test.go b/modules/markup/html_test.go
index 50ea70905c..702c5a716d 100644
--- a/modules/markup/html_test.go
+++ b/modules/markup/html_test.go
@@ -1026,4 +1026,107 @@ func TestRender_FilePreview(t *testing.T) {
localMetas,
)
})
+
+ commitFileURL := util.URLJoin(markup.TestRepoURL, "src", "commit", "c9913120ed2c1e27c1d7752ecdb7a504dc7cf6be", "path", "to", "file.md")
+
+ t.Run("rendered file with ?display=source", func(t *testing.T) {
+ testRender(
+ commitFileURL+"?display=source"+"#L1-L2",
+ `
`+
+ ``+
+ ``+
+ `
`+
+ `
`+
+ ``+
+ ``+
+ ` | `+
+ `# A`+"\n"+` | `+
+ `
`+
+ ``+
+ ` | `+
+ `B`+"\n"+` | `+
+ `
`+
+ ``+
+ `
`+
+ `
`+
+ `
`+
+ ``,
+ localMetas,
+ )
+ })
+
+ t.Run("rendered file without ?display=source", func(t *testing.T) {
+ testRender(
+ commitFileURL+"#L1-L2",
+ ``+
+ ``+
+ ``+
+ `
`+
+ `
`+
+ ``+
+ ``+
+ ` | `+
+ `# A`+"\n"+` | `+
+ `
`+
+ ``+
+ ` | `+
+ `B`+"\n"+` | `+
+ `
`+
+ ``+
+ `
`+
+ `
`+
+ `
`+
+ ``,
+ localMetas,
+ )
+ })
+
+ commitFileURL = util.URLJoin(markup.TestRepoURL, "src", "commit", "190d9492934af498c3f669d6a2431dc5459e5b20", "path", "to", "file.go")
+
+ t.Run("normal file with ?display=source", func(t *testing.T) {
+ testRender(
+ commitFileURL+"?display=source"+"#L2-L3",
+ ``+
+ ``+
+ ``+
+ `
`+
+ `
`+
+ ``+
+ ``+
+ ` | `+
+ `B`+"\n"+` | `+
+ `
`+
+ ``+
+ ` | `+
+ `C`+"\n"+` | `+
+ `
`+
+ ``+
+ `
`+
+ `
`+
+ `
`+
+ ``,
+ localMetas,
+ )
+ })
}
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/0b/b53b56d70d253ce75c257d3cd6334a41ef2b6c b/modules/markup/tests/repo/repo1_filepreview/objects/0b/b53b56d70d253ce75c257d3cd6334a41ef2b6c
new file mode 100644
index 0000000000..1ab268b76c
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/0b/b53b56d70d253ce75c257d3cd6334a41ef2b6c differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/35/75ed7948fe86ab56b0a76f796f7995222bec65 b/modules/markup/tests/repo/repo1_filepreview/objects/35/75ed7948fe86ab56b0a76f796f7995222bec65
new file mode 100644
index 0000000000..1493caa3df
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/35/75ed7948fe86ab56b0a76f796f7995222bec65 differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/3c/95f14e5a0ab2c5ba9ee9a47ddc261af4968043 b/modules/markup/tests/repo/repo1_filepreview/objects/3c/95f14e5a0ab2c5ba9ee9a47ddc261af4968043
new file mode 100644
index 0000000000..3e9c0c0d8b
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/3c/95f14e5a0ab2c5ba9ee9a47ddc261af4968043 differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/72/1f0ce13d83f93d431b849a554a62948b85f573 b/modules/markup/tests/repo/repo1_filepreview/objects/72/1f0ce13d83f93d431b849a554a62948b85f573
new file mode 100644
index 0000000000..d781d4d248
--- /dev/null
+++ b/modules/markup/tests/repo/repo1_filepreview/objects/72/1f0ce13d83f93d431b849a554a62948b85f573
@@ -0,0 +1 @@
+x•ŽKŠ1@]çµ$¿J¥aæz€JRÁ@w+éØsýõ®ÞâñàåÛ²´ÖÛÃè"@VL&J3%f-ÑGDÒq2>FçjBOEݹË:ÀgÃ\1¤œ¦ê¦’kÀêªEM6DÔ,Ÿ\‚âǸÞ:\6é¾OülmÈ©;Ï|ƒ!GäŒE‚£6Z«üzòY¥Î²
¨m¸wÙ›üÂÿi‘.x-o³ò"›úŒLÌ
\ No newline at end of file
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/72/e0a44ea5761c9055995db18019e459576b3b27 b/modules/markup/tests/repo/repo1_filepreview/objects/72/e0a44ea5761c9055995db18019e459576b3b27
new file mode 100644
index 0000000000..7b926dc0d8
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/72/e0a44ea5761c9055995db18019e459576b3b27 differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/72/e1c77b65c7baa0e848557089148833fb54705e b/modules/markup/tests/repo/repo1_filepreview/objects/72/e1c77b65c7baa0e848557089148833fb54705e
new file mode 100644
index 0000000000..0bbca73af2
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/72/e1c77b65c7baa0e848557089148833fb54705e differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/8b/ccd5176c25898b57da2551e076f769054e0d8e b/modules/markup/tests/repo/repo1_filepreview/objects/8b/ccd5176c25898b57da2551e076f769054e0d8e
new file mode 100644
index 0000000000..394a7bb50d
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/8b/ccd5176c25898b57da2551e076f769054e0d8e differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/c9/8762531dd068cd818300a5f5c7dca5da79b510 b/modules/markup/tests/repo/repo1_filepreview/objects/c9/8762531dd068cd818300a5f5c7dca5da79b510
new file mode 100644
index 0000000000..af5b784773
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/c9/8762531dd068cd818300a5f5c7dca5da79b510 differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/objects/c9/913120ed2c1e27c1d7752ecdb7a504dc7cf6be b/modules/markup/tests/repo/repo1_filepreview/objects/c9/913120ed2c1e27c1d7752ecdb7a504dc7cf6be
new file mode 100644
index 0000000000..9fc2b7c312
Binary files /dev/null and b/modules/markup/tests/repo/repo1_filepreview/objects/c9/913120ed2c1e27c1d7752ecdb7a504dc7cf6be differ
diff --git a/modules/markup/tests/repo/repo1_filepreview/refs/heads/master b/modules/markup/tests/repo/repo1_filepreview/refs/heads/master
index df25bf45f0..f3d5d39dd5 100644
--- a/modules/markup/tests/repo/repo1_filepreview/refs/heads/master
+++ b/modules/markup/tests/repo/repo1_filepreview/refs/heads/master
@@ -1 +1 @@
-4c1aaf56bcb9f39dcf65f3f250726850aed13cd6
+c9913120ed2c1e27c1d7752ecdb7a504dc7cf6be
diff --git a/modules/setting/service.go b/modules/setting/service.go
index 9807f33352..7a907023c4 100644
--- a/modules/setting/service.go
+++ b/modules/setting/service.go
@@ -140,6 +140,11 @@ func CompileEmailGlobList(sec ConfigSection, keys ...string) (globs []glob.Glob)
return globs
}
+// LoadServiceSetting loads the service settings
+func LoadServiceSetting() {
+ loadServiceFrom(CfgProvider)
+}
+
func loadServiceFrom(rootCfg ConfigProvider) {
sec := rootCfg.Section("service")
Service.ActiveCodeLives = sec.Key("ACTIVE_CODE_LIVE_MINUTES").MustInt(180)
diff --git a/modules/util/slice.go b/modules/util/slice.go
index 9c878c24be..80c8e62f6f 100644
--- a/modules/util/slice.go
+++ b/modules/util/slice.go
@@ -4,7 +4,6 @@
package util
import (
- "cmp"
"slices"
"strings"
)
@@ -47,13 +46,6 @@ func SliceRemoveAll[T comparable](slice []T, target T) []T {
return slices.DeleteFunc(slice, func(t T) bool { return t == target })
}
-// Sorted returns the sorted slice
-// Note: The parameter is sorted inline.
-func Sorted[S ~[]E, E cmp.Ordered](values S) S {
- slices.Sort(values)
- return values
-}
-
// TODO: Replace with "maps.Values" once available, current it only in golang.org/x/exp/maps but not in standard library
func ValuesOfMap[K comparable, V any](m map[K]V) []V {
values := make([]V, 0, len(m))
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index 2c7dbe69ad..7001c1bf0f 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -644,6 +644,7 @@ team_name_been_taken = The team name is already taken.
team_no_units_error = Allow access to at least one repository section.
email_been_used = The email address is already used.
email_invalid = The email address is invalid.
+email_domain_is_not_allowed = The domain of the user's email address %s conflicts with EMAIL_DOMAIN_ALLOWLIST or EMAIL_DOMAIN_BLOCKLIST. Make sure you have set the email address correctly.
openid_been_used = The OpenID address "%s" is already used.
username_password_incorrect = Username or password is incorrect.
password_complexity = Password does not pass complexity requirements:
diff --git a/routers/web/user/package.go b/routers/web/user/package.go
index 707c86db7a..70ea20d388 100644
--- a/routers/web/user/package.go
+++ b/routers/web/user/package.go
@@ -6,6 +6,7 @@ package user
import (
"fmt"
"net/http"
+ "slices"
"code.gitea.io/gitea/models/db"
org_model "code.gitea.io/gitea/models/organization"
@@ -23,7 +24,6 @@ import (
debian_module "code.gitea.io/gitea/modules/packages/debian"
rpm_module "code.gitea.io/gitea/modules/packages/rpm"
"code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/web"
packages_helper "code.gitea.io/gitea/routers/api/packages/helper"
shared_user "code.gitea.io/gitea/routers/web/shared/user"
@@ -200,9 +200,9 @@ func ViewPackageVersion(ctx *context.Context) {
}
}
- ctx.Data["Branches"] = util.Sorted(branches.Values())
- ctx.Data["Repositories"] = util.Sorted(repositories.Values())
- ctx.Data["Architectures"] = util.Sorted(architectures.Values())
+ ctx.Data["Branches"] = slices.Sorted(branches.Seq())
+ ctx.Data["Repositories"] = slices.Sorted(repositories.Seq())
+ ctx.Data["Architectures"] = slices.Sorted(architectures.Seq())
case packages_model.TypeArch:
ctx.Data["SignMail"] = fmt.Sprintf("%s@noreply.%s", ctx.Package.Owner.Name, setting.Packages.RegistryHost)
groups := make(container.Set[string])
@@ -213,7 +213,7 @@ func ViewPackageVersion(ctx *context.Context) {
}
}
}
- ctx.Data["Groups"] = util.Sorted(groups.Values())
+ ctx.Data["Groups"] = slices.Sorted(groups.Seq())
case packages_model.TypeDebian:
distributions := make(container.Set[string])
components := make(container.Set[string])
@@ -232,9 +232,9 @@ func ViewPackageVersion(ctx *context.Context) {
}
}
- ctx.Data["Distributions"] = util.Sorted(distributions.Values())
- ctx.Data["Components"] = util.Sorted(components.Values())
- ctx.Data["Architectures"] = util.Sorted(architectures.Values())
+ ctx.Data["Distributions"] = slices.Sorted(distributions.Seq())
+ ctx.Data["Components"] = slices.Sorted(components.Seq())
+ ctx.Data["Architectures"] = slices.Sorted(architectures.Seq())
case packages_model.TypeRpm, packages_model.TypeAlt:
groups := make(container.Set[string])
architectures := make(container.Set[string])
@@ -250,8 +250,8 @@ func ViewPackageVersion(ctx *context.Context) {
}
}
- ctx.Data["Groups"] = util.Sorted(groups.Values())
- ctx.Data["Architectures"] = util.Sorted(architectures.Values())
+ ctx.Data["Groups"] = slices.Sorted(groups.Seq())
+ ctx.Data["Architectures"] = slices.Sorted(architectures.Seq())
}
var (
diff --git a/services/doctor/breaking.go b/services/doctor/breaking.go
index 683ec97389..ec8433b8de 100644
--- a/services/doctor/breaking.go
+++ b/services/doctor/breaking.go
@@ -10,6 +10,7 @@ import (
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/validation"
"xorm.io/builder"
@@ -30,6 +31,8 @@ func iterateUserAccounts(ctx context.Context, each func(*user.User) error) error
// addresses would be currently facing a error due to their invalid email address.
// Ref: https://github.com/go-gitea/gitea/pull/19085 & https://github.com/go-gitea/gitea/pull/17688
func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error {
+ setting.LoadServiceSetting()
+
// We could use quirky SQL to get all users that start without a [a-zA-Z0-9], but that would mean
// DB provider-specific SQL and only works _now_. So instead we iterate through all user accounts
// and use the validation.ValidateEmail function to be future-proof.
@@ -61,6 +64,8 @@ func checkUserEmail(ctx context.Context, logger log.Logger, _ bool) error {
// are allowed for various reasons. This check helps with detecting users that, according
// to our reserved names, don't have a valid username.
func checkUserName(ctx context.Context, logger log.Logger, _ bool) error {
+ setting.LoadServiceSetting()
+
var invalidUserCount int64
if err := iterateUserAccounts(ctx, func(u *user.User) error {
if err := user.IsUsableUsername(u.Name); err != nil {
diff --git a/services/packages/alt/repository.go b/services/packages/alt/repository.go
index 7b7951eebb..f49c435e64 100644
--- a/services/packages/alt/repository.go
+++ b/services/packages/alt/repository.go
@@ -711,7 +711,7 @@ func buildRelease(ctx context.Context, pv *packages_model.PackageVersion, pfs []
architectures.Add(pd.FileMetadata.Architecture)
}
- for architecture := range architectures {
+ for architecture := range architectures.Seq() {
version := time.Now().Unix()
label := setting.AppName
data := fmt.Sprintf(`Archive: Alt Linux Team
diff --git a/services/release/release.go b/services/release/release.go
index 876514beec..b52e4b124e 100644
--- a/services/release/release.go
+++ b/services/release/release.go
@@ -372,7 +372,7 @@ func UpdateRelease(ctx context.Context, doer *user_model.User, gitRepo *git.Repo
return err
}
- for _, uuid := range delAttachmentUUIDs.Values() {
+ for uuid := range delAttachmentUUIDs.Seq() {
if err := storage.Attachments.Delete(repo_model.AttachmentRelativePath(uuid)); err != nil {
// Even delete files failed, but the attachments has been removed from database, so we
// should not return error but only record the error on logs.