aboutsummaryrefslogtreecommitdiffstats
path: root/bug/label.go
diff options
context:
space:
mode:
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
+}