diff --git a/link.go b/link.go index 8ff5381..c937aef 100644 --- a/link.go +++ b/link.go @@ -3,11 +3,12 @@ package atomfeed import ( "errors" "fmt" + "strings" ) type Link struct { *CommonAttributes - Title Text `xml:"title,attr,omitempty"` + Title string `xml:"title,attr,omitempty"` Content Content `xml:"content"` // undefinedContent in RFC4287 Href IRI `xml:"href,attr"` Rel string `xml:"rel,attr,omitempty"` @@ -28,12 +29,22 @@ func NewLink(href string) (*Link, error) { func (l *Link) Check() error { if l.Href == "" { return errors.New("href attribute of link empty") + } else { + if !isValidIRI(l.Href) { + return fmt.Errorf("href attribute %v of link not correctly formatted", l.Href) + } } - if l.Title != nil { - if err := l.Title.Check(); err != nil { - return fmt.Errorf("title attribute of link %v: %v", l.Href, err) - } + if strings.Contains(l.Rel, ":") || !isValidIRI(IRI(l.Rel)) { + return fmt.Errorf("rel attribute %v of link %v not correctly formatted", l.Rel, l.Href) + } + + if !isValidMediaType(string(l.Type)) { + return fmt.Errorf("type attribute %v of link %v invalid media type", l.Type, l.Href) + } + + if !isValidLanguageTag(l.HrefLang) { + return fmt.Errorf("hreflang attribute %v of link %v invalid language tag", l.Type, l.HrefLang) } if l.Content == nil {