Properly check url and email address
This commit is contained in:
parent
fe4d539e91
commit
6215ecb82a
14
person.go
14
person.go
@ -4,6 +4,8 @@ import (
|
||||
"encoding/xml"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/mail"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
@ -27,6 +29,18 @@ func (p *Person) Check() error {
|
||||
return errors.New("name element of person element empty")
|
||||
}
|
||||
|
||||
if p.URI != "" {
|
||||
if _, err := url.ParseRequestURI(string(p.URI)); err != nil {
|
||||
return fmt.Errorf("email element of person %v not correctly formatted", p.Name)
|
||||
}
|
||||
}
|
||||
|
||||
if p.Email != "" {
|
||||
if _, err := mail.ParseAddress(string(p.Email)); err != nil {
|
||||
return fmt.Errorf("email element of person %v not correctly formatted", p.Name)
|
||||
}
|
||||
}
|
||||
|
||||
if p.Extensions != nil {
|
||||
for i, e := range p.Extensions {
|
||||
if err := e.Check(); err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user