Merge pull request '[FEAT] Trim spaces from repo names on form submission' (#5822) from gusted/forgejo-trim-spaces-form into forgejo
Some checks are pending
/ release (push) Waiting to run
testing / backend-checks (push) Waiting to run
testing / frontend-checks (push) Waiting to run
testing / test-unit (push) Blocked by required conditions
testing / test-e2e (push) Blocked by required conditions
testing / test-remote-cacher (map[image:docker.io/bitnami/redis:7.2 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:docker.io/bitnami/valkey:7.2 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:ghcr.io/microsoft/garnet-alpine:1.0.14 port:6379]) (push) Blocked by required conditions
testing / test-remote-cacher (map[image:registry.redict.io/redict:7.3.0-scratch port:6379]) (push) Blocked by required conditions
testing / test-mysql (push) Blocked by required conditions
testing / test-pgsql (push) Blocked by required conditions
testing / test-sqlite (push) Blocked by required conditions
testing / security-check (push) Blocked by required conditions

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5822
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Otto 2024-11-06 09:16:17 +00:00
commit 0fb48872ac
31 changed files with 54 additions and 36 deletions

File diff suppressed because one or more lines are too long

2
go.mod
View file

@ -6,6 +6,7 @@ require (
code.forgejo.org/f3/gof3/v3 v3.7.0
code.forgejo.org/forgejo-contrib/go-libravatar v0.0.0-20191008002943-06d1c002b251
code.forgejo.org/forgejo/reply v1.0.2
code.forgejo.org/go-chi/binding v0.0.0-20241105210225-1f8bf5136720
code.forgejo.org/go-chi/cache v0.0.0-20240912103640-dcb08fba860d
code.forgejo.org/go-chi/captcha v0.0.0-20240905153133-df43b9250ed5
code.forgejo.org/go-chi/session v0.0.0-20241017103059-2a992261fc26
@ -14,7 +15,6 @@ require (
code.gitea.io/sdk/gitea v0.17.1
codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570
connectrpc.com/connect v1.17.0
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4
github.com/42wim/sshsig v0.0.0-20211121163825-841cf5bbc121
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358

4
go.sum
View file

@ -10,6 +10,8 @@ code.forgejo.org/forgejo/archiver/v3 v3.5.1 h1:UmmbA7D5550uf71SQjarmrn6yKwOGxtEj
code.forgejo.org/forgejo/archiver/v3 v3.5.1/go.mod h1:e3dqJ7H78uzsRSEACH1joayhuSyhnonssnDhppzS1L4=
code.forgejo.org/forgejo/reply v1.0.2 h1:dMhQCHV6/O3L5CLWNTol+dNzDAuyCK88z4J/lCdgFuQ=
code.forgejo.org/forgejo/reply v1.0.2/go.mod h1:RyZUfzQLc+fuLIGjTSQWDAJWPiL4WtKXB/FifT5fM7U=
code.forgejo.org/go-chi/binding v0.0.0-20241105210225-1f8bf5136720 h1:DDdvrdov1a6HK0xiJIUTfGh1RpKP0prkHi2guxhDKIU=
code.forgejo.org/go-chi/binding v0.0.0-20241105210225-1f8bf5136720/go.mod h1:fWwqaHj0H1/KeCpBqdvKunflq8pYfciEHI5v3UUeE2E=
code.forgejo.org/go-chi/cache v0.0.0-20240912103640-dcb08fba860d h1:nOu/2GX571t4intmtfvpctS148OqsBYrGUySVm93ifc=
code.forgejo.org/go-chi/cache v0.0.0-20240912103640-dcb08fba860d/go.mod h1:OVlZ/TqDYJ+RUJ+R+J+OLxtlyjo3pbjBeK7LAWAB+Vk=
code.forgejo.org/go-chi/captcha v0.0.0-20240905153133-df43b9250ed5 h1:A7P1liXCpJBHEJ5KIDsF0ujnQ8FQ/aX1UixTW0vGrDQ=
@ -32,8 +34,6 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4HHsCo6xi2oWZYKWW4bly/Ory9FuTpFPRxj/mAg=
git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs=
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed h1:EZZBtilMLSZNWtHHcgq2mt6NSGhJSZBuduAlinMEmso=
gitea.com/go-chi/binding v0.0.0-20240430071103-39a851e106ed/go.mod h1:E3i3cgB04dDx0v3CytCgRTTn9Z/9x891aet3r456RVw=
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4 h1:IFT+hup2xejHqdhS7keYWioqfmxdnfblFDTGoOwcZ+o=
gitea.com/lunny/levelqueue v0.4.2-0.20230414023320-3c0159fe0fe4/go.mod h1:HBqmLbz56JWpfEGG0prskAV97ATNRoj5LDmPicD22hU=
gitea.com/xorm/sqlfiddle v0.0.0-20180821085327-62ce714f951a h1:lSA0F4e9A2NcQSqGqTOXqu2aRi/XEQxDCBwM8yJtE6s=

View file

@ -13,7 +13,7 @@ import (
"code.gitea.io/gitea/modules/container"
api "code.gitea.io/gitea/modules/structs"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// Validate checks whether an IssueTemplate is considered valid, and returns the first error

View file

@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/git"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
"github.com/gobwas/glob"
)

View file

@ -8,7 +8,7 @@ import (
"net/http/httptest"
"testing"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
chi "github.com/go-chi/chi/v5"
"github.com/stretchr/testify/assert"
)

View file

@ -6,7 +6,7 @@ package validation
import (
"testing"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
"github.com/gobwas/glob"
)

View file

@ -6,7 +6,7 @@ package validation
import (
"testing"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
var gitRefNameValidationTestCases = []validationTestCase{

View file

@ -7,7 +7,7 @@ import (
"regexp"
"testing"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
func getRegexPatternErrorString(pattern string) string {

View file

@ -6,7 +6,7 @@ package validation
import (
"testing"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
var urlValidationTestCases = []validationTestCase{

View file

@ -13,7 +13,7 @@ import (
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/modules/validation"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// Form form binding interface

View file

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
"github.com/go-chi/chi/v5"
)

View file

@ -103,7 +103,7 @@ import (
_ "code.gitea.io/gitea/routers/api/v1/swagger" // for swagger generation
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
func sudo() func(ctx *context.APIContext) {

View file

@ -15,7 +15,7 @@ import (
"code.gitea.io/gitea/modules/web"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
chi_middleware "github.com/go-chi/chi/v5/middleware"
)

View file

@ -40,7 +40,7 @@ import (
remote_service "code.gitea.io/gitea/services/remote"
user_service "code.gitea.io/gitea/services/user"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
"github.com/golang-jwt/jwt/v5"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"

View file

@ -58,7 +58,7 @@ import (
pull_service "code.gitea.io/gitea/services/pull"
repo_service "code.gitea.io/gitea/services/repository"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
const (

View file

@ -28,7 +28,7 @@ import (
"code.gitea.io/gitea/services/forms"
webhook_service "code.gitea.io/gitea/services/webhook"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
const (

View file

@ -10,7 +10,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// AdminCreateUserForm form for admin to create user

View file

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// AuthenticationForm form for authentication

View file

@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// ________ .__ __ .__

View file

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
type PackageCleanupRuleForm struct {

View file

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// NewBranchForm form for creating a new branch

View file

@ -21,13 +21,13 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// CreateRepoForm form for creating repository
type CreateRepoForm struct {
UID int64 `binding:"Required"`
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)" preprocess:"TrimSpace"`
Private bool
Description string `binding:"MaxSize(2048)"`
DefaultBranch string `binding:"GitRefName;MaxSize(100)"`

View file

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// ProtectTagForm form for changing protected tag settings

View file

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// EditRunnerForm form for admin to create runner

View file

@ -16,7 +16,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// InstallForm form for installation page

View file

@ -9,7 +9,7 @@ import (
"code.gitea.io/gitea/modules/web/middleware"
"code.gitea.io/gitea/services/context"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
// SignInOpenIDForm form for signing in with OpenID

View file

@ -26,7 +26,7 @@ import (
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/webhook/shared"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
type discordHandler struct{}

View file

@ -22,7 +22,7 @@ import (
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/webhook/shared"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
)
type slackHandler struct{}

View file

@ -24,7 +24,7 @@ import (
"code.gitea.io/gitea/services/forms"
"code.gitea.io/gitea/services/webhook/shared"
"gitea.com/go-chi/binding"
"code.forgejo.org/go-chi/binding"
"gopkg.in/yaml.v3"
)

View file

@ -11,9 +11,11 @@ import (
"strings"
"testing"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/test"
"code.gitea.io/gitea/modules/translation"
"code.gitea.io/gitea/tests"
@ -135,3 +137,19 @@ func TestRepoGenerateToOrg(t *testing.T) {
testRepoGenerate(t, session, "44", "user27", "template1", user, org, "generated2")
}
func TestRepoCreateFormTrimSpace(t *testing.T) {
defer tests.PrepareTestEnv(t)()
user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
session := loginUser(t, user.Name)
req := NewRequestWithValues(t, "POST", "/repo/create", map[string]string{
"_csrf": GetCSRF(t, session, "/repo/create"),
"uid": "2",
"repo_name": " spaced-name ",
})
resp := session.MakeRequest(t, req, http.StatusSeeOther)
assert.EqualValues(t, "/user2/spaced-name", test.RedirectURL(resp))
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{OwnerID: 2, Name: "spaced-name"})
}