Change title to string type and add checks
This commit is contained in:
parent
4fe133a394
commit
f8c36a7045
21
link.go
21
link.go
@ -3,11 +3,12 @@ package atomfeed
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Link struct {
|
type Link struct {
|
||||||
*CommonAttributes
|
*CommonAttributes
|
||||||
Title Text `xml:"title,attr,omitempty"`
|
Title string `xml:"title,attr,omitempty"`
|
||||||
Content Content `xml:"content"` // undefinedContent in RFC4287
|
Content Content `xml:"content"` // undefinedContent in RFC4287
|
||||||
Href IRI `xml:"href,attr"`
|
Href IRI `xml:"href,attr"`
|
||||||
Rel string `xml:"rel,attr,omitempty"`
|
Rel string `xml:"rel,attr,omitempty"`
|
||||||
@ -28,12 +29,22 @@ func NewLink(href string) (*Link, error) {
|
|||||||
func (l *Link) Check() error {
|
func (l *Link) Check() error {
|
||||||
if l.Href == "" {
|
if l.Href == "" {
|
||||||
return errors.New("href attribute of link empty")
|
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 strings.Contains(l.Rel, ":") || !isValidIRI(IRI(l.Rel)) {
|
||||||
if err := l.Title.Check(); err != nil {
|
return fmt.Errorf("rel attribute %v of link %v not correctly formatted", l.Rel, l.Href)
|
||||||
return fmt.Errorf("title attribute of link %v: %v", l.Href, err)
|
}
|
||||||
}
|
|
||||||
|
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 {
|
if l.Content == nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user