From aad9e67805a4b279f348f2889646f5d204c1770e Mon Sep 17 00:00:00 2001 From: Sol Fisher Romanoff Date: Sun, 8 Aug 2021 19:03:55 +0300 Subject: [PATCH] Make repo names match [A-Za-z0-9._-]+ Repository names in URLs are now case-insensitive -- This might break existing repositories. Also prohibits use of '.git' and '.hg' as repo names. --- api/graph/resolver.go | 2 +- api/graph/schema.resolvers.go | 3 +++ gitsrht-shell/main.go | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/api/graph/resolver.go b/api/graph/resolver.go index cd01693..b723543 100644 --- a/api/graph/resolver.go +++ b/api/graph/resolver.go @@ -9,5 +9,5 @@ import ( type Resolver struct {} var ( - repoNameRE = regexp.MustCompile(`^[A-Za-z._-][A-Za-z0-9._-]*$`) + repoNameRE = regexp.MustCompile(`^[A-Za-z0-9._-]+$`) ) diff --git a/api/graph/schema.resolvers.go b/api/graph/schema.resolvers.go index a96e953..ee00307 100644 --- a/api/graph/schema.resolvers.go +++ b/api/graph/schema.resolvers.go @@ -75,6 +75,9 @@ func (r *mutationResolver) CreateRepository(ctx context.Context, name string, vi if name == "." || name == ".." { return nil, fmt.Errorf("Invalid repository name '%s' (must not be . or ..)", name) } + if name == ".git" || name == ".hg" { + return nil, fmt.Errorf("Invalid repository name '%s' (must not be .git or .hg)", name) + } conf := config.ForContext(ctx) repoStore, ok := conf.Get("git.sr.ht", "repos") diff --git a/gitsrht-shell/main.go b/gitsrht-shell/main.go index 308de4e..c6cea3c 100644 --- a/gitsrht-shell/main.go +++ b/gitsrht-shell/main.go @@ -264,9 +264,9 @@ func main() { if needsAccess == ACCESS_WRITE { if matched, _ := regexp.MatchString( - `^[A-Za-z._-][A-Za-z0-9._-]*$`, repoName); !matched { + `^[A-Za-z0-9._-]+$`, repoName); !matched { - log.Println("Name must match [A-Za-z._-][A-Za-z0-9._-]*.") + log.Println("Name must match [A-Za-z0-9._-]+.") notFound("name policy", nil) } -- 2.38.4