aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslene <vslene@gmail.com>2014-03-20 23:55:11 +0800
committerslene <vslene@gmail.com>2014-03-20 23:55:11 +0800
commit28b4b6c9d558e340ca8a2e53ec5d729760738305 (patch)
tree8acf7722c7a25341100d46da6728b38e7ba9c334
parentc44aa757d05c2711da1c6e90c0d9d73bcd387433 (diff)
parenta3c1c1d9c88dce4b52379f60754c3dc9fc2a68ea (diff)
downloadgitea-28b4b6c9d558e340ca8a2e53ec5d729760738305.tar.gz
gitea-28b4b6c9d558e340ca8a2e53ec5d729760738305.zip
Merge branch 'master' of github.com:gogits/gogs
-rw-r--r--README.md2
-rw-r--r--gogs.go2
-rw-r--r--models/repo.go31
-rw-r--r--models/user.go5
-rw-r--r--routers/repo/repo.go3
-rw-r--r--routers/repo/single.go5
-rw-r--r--routers/user/user.go8
7 files changed, 51 insertions, 5 deletions
diff --git a/README.md b/README.md
index 3a1023c6d9..4219e4ed03 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language.
Since we choose to use pure Go implementation of Git manipulation, Gogs certainly supports **ALL platforms** that Go supports, including Linux, Max OS X, and Windows with **ZERO** dependency.
-##### Current version: 0.1.1 Alpha
+##### Current version: 0.1.4 Alpha
## Purpose
diff --git a/gogs.go b/gogs.go
index d32e3908c9..a600c53d12 100644
--- a/gogs.go
+++ b/gogs.go
@@ -20,7 +20,7 @@ import (
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true
-const APP_VER = "0.1.2.0320.1"
+const APP_VER = "0.1.3.0320.1"
func init() {
base.AppVer = APP_VER
diff --git a/models/repo.go b/models/repo.go
index 052341ff6e..bcbc586785 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -12,6 +12,7 @@ import (
"os"
"path"
"path/filepath"
+ "regexp"
"strings"
"sync"
"time"
@@ -82,6 +83,7 @@ var (
ErrRepoAlreadyExist = errors.New("Repository already exist")
ErrRepoNotExist = errors.New("Repository does not exist")
ErrRepoFileNotExist = errors.New("Target Repo file does not exist")
+ ErrRepoNameIllegal = errors.New("Repository name contains illegal characters")
)
func init() {
@@ -104,6 +106,15 @@ func init() {
os.Exit(2)
}
}
+
+ // Initialize illegal patterns.
+ for i := range illegalPatterns[1:] {
+ pattern := ""
+ for j := range illegalPatterns[i+1] {
+ pattern += "[" + string(illegalPatterns[i+1][j]-32) + string(illegalPatterns[i+1][j]) + "]"
+ }
+ illegalPatterns[i+1] = pattern
+ }
}
// IsRepositoryExist returns true if the repository with given name under user has already existed.
@@ -120,8 +131,28 @@ func IsRepositoryExist(user *User, repoName string) (bool, error) {
return s.IsDir(), nil
}
+var (
+ // Define as all lower case!!
+ illegalPatterns = []string{"[.][Gg][Ii][Tt]", "user", "help", "stars", "issues", "pulls", "commits", "admin", "repo", "template"}
+)
+
+// IsLegalName returns false if name contains illegal characters.
+func IsLegalName(repoName string) bool {
+ for _, pattern := range illegalPatterns {
+ has, _ := regexp.MatchString(pattern, repoName)
+ if has {
+ return false
+ }
+ }
+ return true
+}
+
// CreateRepository creates a repository for given user or orgnaziation.
func CreateRepository(user *User, repoName, desc, repoLang, license string, private bool, initReadme bool) (*Repository, error) {
+ if !IsLegalName(repoName) {
+ return nil, ErrRepoNameIllegal
+ }
+
isExist, err := IsRepositoryExist(user, repoName)
if err != nil {
return nil, err
diff --git a/models/user.go b/models/user.go
index fd89af6b3f..990e1954a5 100644
--- a/models/user.go
+++ b/models/user.go
@@ -79,6 +79,7 @@ var (
ErrUserAlreadyExist = errors.New("User already exist")
ErrUserNotExist = errors.New("User does not exist")
ErrEmailAlreadyUsed = errors.New("E-mail already used")
+ ErrUserNameIllegal = errors.New("User name contains illegal characters")
)
// IsUserExist checks if given user name exist,
@@ -108,6 +109,10 @@ func GetUserSalt() string {
// RegisterUser creates record of a new user.
func RegisterUser(user *User) (*User, error) {
+ if !IsLegalName(user.Name) {
+ return nil, ErrUserNameIllegal
+ }
+
isExist, err := IsUserExist(user.Name)
if err != nil {
return nil, err
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 556cc4343c..c83a6df522 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -31,6 +31,9 @@ func Create(ctx *middleware.Context, form auth.CreateRepoForm) {
} else if err == models.ErrRepoAlreadyExist {
ctx.RenderWithErr("Repository name has already been used", "repo/create", &form)
return
+ } else if err == models.ErrRepoNameIllegal {
+ ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "repo/create", &form)
+ return
}
ctx.Handle(200, "repo.Create", err)
}
diff --git a/routers/repo/single.go b/routers/repo/single.go
index f1b15cceed..eab49be919 100644
--- a/routers/repo/single.go
+++ b/routers/repo/single.go
@@ -217,6 +217,11 @@ func Setting(ctx *middleware.Context, params martini.Params) {
title = t
}
+ if len(params["branchname"]) == 0 {
+ params["branchname"] = "master"
+ }
+
+ ctx.Data["Branchname"] = params["branchname"]
ctx.Data["Title"] = title + " - settings"
ctx.HTML(200, "repo/setting")
}
diff --git a/routers/user/user.go b/routers/user/user.go
index be2c4d3839..ea6922591e 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -139,11 +139,13 @@ func SignUp(ctx *middleware.Context, form auth.RegisterForm) {
var err error
if u, err = models.RegisterUser(u); err != nil {
- switch err.Error() {
- case models.ErrUserAlreadyExist.Error():
+ switch err {
+ case models.ErrUserAlreadyExist:
ctx.RenderWithErr("Username has been already taken", "user/signup", &form)
- case models.ErrEmailAlreadyUsed.Error():
+ case models.ErrEmailAlreadyUsed:
ctx.RenderWithErr("E-mail address has been already used", "user/signup", &form)
+ case models.ErrUserNameIllegal:
+ ctx.RenderWithErr(models.ErrRepoNameIllegal.Error(), "user/signup", &form)
default:
ctx.Handle(200, "user.SignUp", err)
}