summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-07-23 15:59:19 +0800
committerUnknwon <u@gogs.io>2016-07-23 15:59:19 +0800
commitc912494609470f10401594391c6f2763684cb624 (patch)
tree1f8c047fbb9ed1ae0f852d8899cb037dfd80a47e /models
parent69dae1ec1c5265e815c8b0fedff3399438e2e380 (diff)
downloadgitea-c912494609470f10401594391c6f2763684cb624.tar.gz
gitea-c912494609470f10401594391c6f2763684cb624.zip
#3076 detect invalid tag name git error
Diffstat (limited to 'models')
-rw-r--r--models/error.go19
-rw-r--r--models/release.go5
2 files changed, 20 insertions, 4 deletions
diff --git a/models/error.go b/models/error.go
index 69b2962475..a6cf31218c 100644
--- a/models/error.go
+++ b/models/error.go
@@ -387,7 +387,7 @@ func IsErrReleaseAlreadyExist(err error) bool {
}
func (err ErrReleaseAlreadyExist) Error() string {
- return fmt.Sprintf("Release tag already exist [tag_name: %s]", err.TagName)
+ return fmt.Sprintf("release tag already exist [tag_name: %s]", err.TagName)
}
type ErrReleaseNotExist struct {
@@ -401,7 +401,20 @@ func IsErrReleaseNotExist(err error) bool {
}
func (err ErrReleaseNotExist) Error() string {
- return fmt.Sprintf("Release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
+ return fmt.Sprintf("release tag does not exist [id: %d, tag_name: %s]", err.ID, err.TagName)
+}
+
+type ErrInvalidTagName struct {
+ TagName string
+}
+
+func IsErrInvalidTagName(err error) bool {
+ _, ok := err.(ErrInvalidTagName)
+ return ok
+}
+
+func (err ErrInvalidTagName) Error() string {
+ return fmt.Sprintf("release tag name is not valid [tag_name: %s]", err.TagName)
}
// __________ .__
@@ -421,7 +434,7 @@ func IsErrBranchNotExist(err error) bool {
}
func (err ErrBranchNotExist) Error() string {
- return fmt.Sprintf("Branch does not exist [name: %s]", err.Name)
+ return fmt.Sprintf("branch does not exist [name: %s]", err.Name)
}
// __ __ ___. .__ __
diff --git a/models/release.go b/models/release.go
index 026ab8ff5c..2355ef3092 100644
--- a/models/release.go
+++ b/models/release.go
@@ -67,9 +67,12 @@ func createTag(gitRepo *git.Repository, rel *Release) error {
return fmt.Errorf("GetBranchCommit: %v", err)
}
- // Trim '--' prefix to prevent command line argument vulnerability
+ // Trim '--' prefix to prevent command line argument vulnerability.
rel.TagName = strings.TrimPrefix(rel.TagName, "--")
if err = gitRepo.CreateTag(rel.TagName, commit.ID.String()); err != nil {
+ if strings.Contains(err.Error(), "is not a valid tag name") {
+ return ErrInvalidTagName{rel.TagName}
+ }
return err
}
} else {