No more undefined content in link and category

It seems that undefined content is only mentioned in RFC4287 because
link and category are elements and those usually need some content.
This commit is contained in:
Jason Streifling 2024-10-17 18:57:43 +02:00
parent e73b78ef30
commit d11b229691
2 changed files with 7 additions and 33 deletions

View File

@ -8,21 +8,14 @@ import (
type Category struct {
*CommonAttributes
Content string `xml:",chardata"` // undefinedContent in RFC4287
Term string `xml:"term,attr"`
Scheme IRI `xml:"scheme,attr,omitempty"`
Label string `xml:"label,attr,omitempty"`
Term string `xml:"term,attr"`
Scheme IRI `xml:"scheme,attr,omitempty"`
Label string `xml:"label,attr,omitempty"`
}
// NewCategory creates a new Category. It returns a *Category and an error.
func NewCategory(term, content string) (*Category, error) {
if content != "" {
if !isValidXML(content) {
return nil, fmt.Errorf("%v not valid XML", content)
}
}
return &Category{Term: term, Content: content}, nil
func NewCategory(term string) *Category {
return &Category{Term: term}
}
// SetLabel sets the label of the Category.
@ -47,11 +40,5 @@ func (c *Category) Check() error {
return fmt.Errorf("label attribute %v of category not correctly escaped", c.Label)
}
if c.Content != "" {
if !isValidXML(c.Content) {
return fmt.Errorf("content element %v of category not valid XML", c.Content)
}
}
return nil
}

17
link.go
View File

@ -9,7 +9,6 @@ import (
type Link struct {
*CommonAttributes
Title string `xml:"title,attr,omitempty"`
Content string `xml:",chardata"` // undefinedContent in RFC4287
Href IRI `xml:"href,attr"`
Rel string `xml:"rel,attr,omitempty"`
Type MediaType `xml:"type,attr,omitempty"`
@ -18,14 +17,8 @@ type Link struct {
}
// NewLink creates a new Link. It returns a *Link and an error.
func NewLink(href, content string) (*Link, error) {
if content != "" {
if !isValidXML(content) {
return nil, fmt.Errorf("%v not valid XML", content)
}
}
return &Link{Href: IRI(href), Content: content}, nil
func NewLink(href, content string) *Link {
return &Link{Href: IRI(href)}
}
// Check checks the Link for incompatibilities with RFC4287. It returns an
@ -57,12 +50,6 @@ func (l *Link) Check() error {
}
}
if l.Content != "" {
if !isValidXML(l.Content) {
return fmt.Errorf("content element %v of link not valid XML", l.Content)
}
}
return nil
}