mirror of
https://github.com/goharbor/harbor.git
synced 2024-11-26 04:05:40 +01:00
commit
733a9fd628
@ -44,7 +44,8 @@ type projectReq struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const projectNameMaxLen int = 30
|
const projectNameMaxLen int = 30
|
||||||
const projectNameMinLen int = 4
|
const projectNameMinLen int = 2
|
||||||
|
const restrictedNameChars = `[a-z0-9]+(?:[._-][a-z0-9]+)*`
|
||||||
const dupProjectPattern = `Duplicate entry '\w+' for key 'name'`
|
const dupProjectPattern = `Duplicate entry '\w+' for key 'name'`
|
||||||
|
|
||||||
// Prepare validates the URL and the user
|
// Prepare validates the URL and the user
|
||||||
@ -417,9 +418,9 @@ func isProjectAdmin(userID int, pid int64) bool {
|
|||||||
func validateProjectReq(req projectReq) error {
|
func validateProjectReq(req projectReq) error {
|
||||||
pn := req.ProjectName
|
pn := req.ProjectName
|
||||||
if isIllegalLength(req.ProjectName, projectNameMinLen, projectNameMaxLen) {
|
if isIllegalLength(req.ProjectName, projectNameMinLen, projectNameMaxLen) {
|
||||||
return fmt.Errorf("Project name is illegal in length. (greater than 4 or less than 30)")
|
return fmt.Errorf("Project name is illegal in length. (greater than 2 or less than 30)")
|
||||||
}
|
}
|
||||||
validProjectName := regexp.MustCompile(`^[a-z0-9](?:-*[a-z0-9])*(?:[._][a-z0-9](?:-*[a-z0-9])*)*$`)
|
validProjectName := regexp.MustCompile(`^` + restrictedNameChars + `$`)
|
||||||
legal := validProjectName.MatchString(pn)
|
legal := validProjectName.MatchString(pn)
|
||||||
if !legal {
|
if !legal {
|
||||||
return fmt.Errorf("project name is not in lower case or contains illegal characters")
|
return fmt.Errorf("project name is not in lower case or contains illegal characters")
|
||||||
|
Loading…
Reference in New Issue
Block a user