~edwargix/git.sr.ht

aad9e67805a4b279f348f2889646f5d204c1770e — Sol Fisher Romanoff 3 years ago 6652abb
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.
3 files changed, 6 insertions(+), 3 deletions(-)

M api/graph/resolver.go
M api/graph/schema.resolvers.go
M gitsrht-shell/main.go
M api/graph/resolver.go => api/graph/resolver.go +1 -1
@@ 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._-]+$`)
)

M api/graph/schema.resolvers.go => api/graph/schema.resolvers.go +3 -0
@@ 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")

M gitsrht-shell/main.go => gitsrht-shell/main.go +2 -2
@@ 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)
				}