diff options
author | Michael Muré <batolettre@gmail.com> | 2018-09-15 13:15:00 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2018-09-15 13:15:00 +0200 |
commit | 7bec0b1f134d213e7505fc2ac03ffea26f2193cc (patch) | |
tree | e263cccd84406843eacbc6bd184acdacb25a49d1 /bug/label.go | |
parent | b478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (diff) | |
download | git-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.go | 21 |
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 +} |