aboutsummaryrefslogtreecommitdiffstats
path: root/bug/person.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/person.go
parentb478cd1bcb4756b20f7f4b15fcf81f23e1a60a02 (diff)
downloadgit-bug-7bec0b1f134d213e7505fc2ac03ffea26f2193cc.tar.gz
bug: add a data validation process to avoid merging incorrect operations
Diffstat (limited to 'bug/person.go')
-rw-r--r--bug/person.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/bug/person.go b/bug/person.go
index d9f1108b..9fa86804 100644
--- a/bug/person.go
+++ b/bug/person.go
@@ -2,9 +2,11 @@ package bug
import (
"errors"
+ "fmt"
"strings"
"github.com/MichaelMure/git-bug/repository"
+ "github.com/MichaelMure/git-bug/util/text"
)
type Person struct {
@@ -37,3 +39,27 @@ func GetUser(repo repository.Repo) (Person, error) {
func (p Person) Match(query string) bool {
return strings.Contains(strings.ToLower(p.Name), strings.ToLower(query))
}
+
+func (p Person) Validate() error {
+ if text.Empty(p.Name) {
+ return fmt.Errorf("name is not set")
+ }
+
+ if strings.Contains(p.Name, "\n") {
+ return fmt.Errorf("name should be a single line")
+ }
+
+ if !text.Safe(p.Name) {
+ return fmt.Errorf("name is not fully printable")
+ }
+
+ if strings.Contains(p.Email, "\n") {
+ return fmt.Errorf("email should be a single line")
+ }
+
+ if !text.Safe(p.Email) {
+ return fmt.Errorf("email is not fully printable")
+ }
+
+ return nil
+}