| @@ -3,7 +3,7 @@ Gogs - Go Git Service [ |  | ||||
| ##### Current tip version: 0.9.51 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) | |||||
| ##### Current tip version: 0.9.52 (see [Releases](https://github.com/gogits/gogs/releases) for binary versions) | |||||
| | Web | UI | Preview | | | Web | UI | Preview | | ||||
| |:-------------:|:-------:|:-------:| | |:-------------:|:-------:|:-------:| | ||||
| @@ -17,7 +17,7 @@ import ( | |||||
| "github.com/gogits/gogs/modules/setting" | "github.com/gogits/gogs/modules/setting" | ||||
| ) | ) | ||||
| const APP_VER = "0.9.51.0723" | |||||
| const APP_VER = "0.9.52.0723" | |||||
| func init() { | func init() { | ||||
| runtime.GOMAXPROCS(runtime.NumCPU()) | runtime.GOMAXPROCS(runtime.NumCPU()) | ||||
| @@ -94,7 +94,7 @@ func (org *User) RemoveOrgRepo(repoID int64) error { | |||||
| // CreateOrganization creates record of a new organization. | // CreateOrganization creates record of a new organization. | ||||
| func CreateOrganization(org, owner *User) (err error) { | func CreateOrganization(org, owner *User) (err error) { | ||||
| if err = IsUsableName(org.Name); err != nil { | |||||
| if err = IsUsableUsername(org.Name); err != nil { | |||||
| return err | return err | ||||
| } | } | ||||
| @@ -19,7 +19,6 @@ import ( | |||||
| "strings" | "strings" | ||||
| "sync" | "sync" | ||||
| "time" | "time" | ||||
| "unicode/utf8" | |||||
| "github.com/Unknwon/cae/zip" | "github.com/Unknwon/cae/zip" | ||||
| "github.com/Unknwon/com" | "github.com/Unknwon/com" | ||||
| @@ -517,34 +516,6 @@ func (repo *Repository) CloneLink() (cl *CloneLink) { | |||||
| return repo.cloneLink(false) | return repo.cloneLink(false) | ||||
| } | } | ||||
| var ( | |||||
| reservedNames = []string{"debug", "raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "new", ".", ".."} | |||||
| reservedPatterns = []string{"*.git", "*.keys", "*.wiki"} | |||||
| ) | |||||
| // IsUsableName checks if name is reserved or pattern of name is not allowed. | |||||
| func IsUsableName(name string) error { | |||||
| name = strings.TrimSpace(strings.ToLower(name)) | |||||
| if utf8.RuneCountInString(name) == 0 { | |||||
| return ErrNameEmpty | |||||
| } | |||||
| for i := range reservedNames { | |||||
| if name == reservedNames[i] { | |||||
| return ErrNameReserved{name} | |||||
| } | |||||
| } | |||||
| for _, pat := range reservedPatterns { | |||||
| if pat[0] == '*' && strings.HasSuffix(name, pat[1:]) || | |||||
| (pat[len(pat)-1] == '*' && strings.HasPrefix(name, pat[:len(pat)-1])) { | |||||
| return ErrNamePatternNotAllowed{pat} | |||||
| } | |||||
| } | |||||
| return nil | |||||
| } | |||||
| // Mirror represents a mirror information of repository. | // Mirror represents a mirror information of repository. | ||||
| type Mirror struct { | type Mirror struct { | ||||
| ID int64 `xorm:"pk autoincr"` | ID int64 `xorm:"pk autoincr"` | ||||
| @@ -940,8 +911,17 @@ func initRepository(e Engine, repoPath string, u *User, repo *Repository, opts C | |||||
| return nil | return nil | ||||
| } | } | ||||
| var ( | |||||
| reservedRepoNames = []string{".", ".."} | |||||
| reservedRepoPatterns = []string{"*.git", "*.wiki"} | |||||
| ) | |||||
| func IsUsableRepoName(name string) error { | |||||
| return isUsableName(reservedRepoNames, reservedRepoPatterns, name) | |||||
| } | |||||
| func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) { | func createRepository(e *xorm.Session, u *User, repo *Repository) (err error) { | ||||
| if err = IsUsableName(repo.Name); err != nil { | |||||
| if err = IsUsableRepoName(repo.Name); err != nil { | |||||
| return err | return err | ||||
| } | } | ||||
| @@ -1209,7 +1189,7 @@ func TransferOwnership(u *User, newOwnerName string, repo *Repository) error { | |||||
| func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) { | func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error) { | ||||
| oldRepoName = strings.ToLower(oldRepoName) | oldRepoName = strings.ToLower(oldRepoName) | ||||
| newRepoName = strings.ToLower(newRepoName) | newRepoName = strings.ToLower(newRepoName) | ||||
| if err = IsUsableName(newRepoName); err != nil { | |||||
| if err = IsUsableRepoName(newRepoName); err != nil { | |||||
| return err | return err | ||||
| } | } | ||||
| @@ -18,6 +18,7 @@ import ( | |||||
| "path/filepath" | "path/filepath" | ||||
| "strings" | "strings" | ||||
| "time" | "time" | ||||
| "unicode/utf8" | |||||
| "github.com/Unknwon/com" | "github.com/Unknwon/com" | ||||
| "github.com/go-xorm/xorm" | "github.com/go-xorm/xorm" | ||||
| @@ -468,9 +469,43 @@ func NewFakeUser() *User { | |||||
| } | } | ||||
| } | } | ||||
| var ( | |||||
| reversedUsernames = []string{"debug", "raw", "install", "api", "avatar", "user", "org", "help", "stars", "issues", "pulls", "commits", "repo", "template", "admin", "new", ".", ".."} | |||||
| reversedUserPatterns = []string{"*.keys"} | |||||
| ) | |||||
| // isUsableName checks if name is reserved or pattern of name is not allowed | |||||
| // based on given reversed names and patterns. | |||||
| // Names are exact match, patterns can be prefix or suffix match with placeholder '*'. | |||||
| func isUsableName(names, patterns []string, name string) error { | |||||
| name = strings.TrimSpace(strings.ToLower(name)) | |||||
| if utf8.RuneCountInString(name) == 0 { | |||||
| return ErrNameEmpty | |||||
| } | |||||
| for i := range names { | |||||
| if name == names[i] { | |||||
| return ErrNameReserved{name} | |||||
| } | |||||
| } | |||||
| for _, pat := range patterns { | |||||
| if pat[0] == '*' && strings.HasSuffix(name, pat[1:]) || | |||||
| (pat[len(pat)-1] == '*' && strings.HasPrefix(name, pat[:len(pat)-1])) { | |||||
| return ErrNamePatternNotAllowed{pat} | |||||
| } | |||||
| } | |||||
| return nil | |||||
| } | |||||
| func IsUsableUsername(name string) error { | |||||
| return isUsableName(reversedUsernames, reversedUserPatterns, name) | |||||
| } | |||||
| // CreateUser creates record of a new user. | // CreateUser creates record of a new user. | ||||
| func CreateUser(u *User) (err error) { | func CreateUser(u *User) (err error) { | ||||
| if err = IsUsableName(u.Name); err != nil { | |||||
| if err = IsUsableUsername(u.Name); err != nil { | |||||
| return err | return err | ||||
| } | } | ||||
| @@ -583,7 +618,7 @@ func VerifyActiveEmailCode(code, email string) *EmailAddress { | |||||
| // ChangeUserName changes all corresponding setting from old user name to new one. | // ChangeUserName changes all corresponding setting from old user name to new one. | ||||
| func ChangeUserName(u *User, newUserName string) (err error) { | func ChangeUserName(u *User, newUserName string) (err error) { | ||||
| if err = IsUsableName(newUserName); err != nil { | |||||
| if err = IsUsableUsername(newUserName); err != nil { | |||||
| return err | return err | ||||
| } | } | ||||
| @@ -1 +1 @@ | |||||
| 0.9.51.0723 | |||||
| 0.9.52.0723 | |||||