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/person.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/person.go')
-rw-r--r-- | bug/person.go | 26 |
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 +} |