aboutsummaryrefslogtreecommitdiffstats
path: root/bug/label.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-15 13:15:00 +0200
commit7bec0b1f134d213e7505fc2ac03ffea26f2193cc (patch)
treee263cccd84406843eacbc6bd184acdacb25a49d1 /bug/label.go
parentb478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (diff)
downloadgit-bug-7bec0b1f134d213e7505fc2ac03ffea26f2193cc.tar.gz
bug: add a data validation process to avoid merging incorrect operations
Diffstat (limited to 'bug/label.go')
-rw-r--r--bug/label.go21
1 files changed, 21 insertions, 0 deletions
diff --git a/bug/label.go b/bug/label.go
index b19a980f..b73222dd 100644
--- a/bug/label.go
+++ b/bug/label.go
@@ -3,6 +3,9 @@ package bug
import (
"fmt"
"io"
+ "strings"
+
+ "github.com/MichaelMure/git-bug/util/text"
)
type Label string
@@ -27,3 +30,21 @@ func (l *Label) UnmarshalGQL(v interface{}) error {
func (l Label) MarshalGQL(w io.Writer) {
w.Write([]byte(`"` + l.String() + `"`))
}
+
+func (l Label) Validate() error {
+ str := string(l)
+
+ if text.Empty(str) {
+ return fmt.Errorf("empty")
+ }
+
+ if strings.Contains(str, "\n") {
+ return fmt.Errorf("should be a single line")
+ }
+
+ if !text.Safe(str) {
+ return fmt.Errorf("not fully printable")
+ }
+
+ return nil
+}