From f8c36a7045f7ee1d63d818fb57af473fc667721b Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 16 Oct 2024 18:31:13 +0200 Subject: [PATCH] Change title to string type and add checks --- link.go | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) 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 {