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