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 { type Category struct {
*CommonAttributes *CommonAttributes
Content string `xml:",chardata"` // undefinedContent in RFC4287 Term string `xml:"term,attr"`
Term string `xml:"term,attr"` Scheme IRI `xml:"scheme,attr,omitempty"`
Scheme IRI `xml:"scheme,attr,omitempty"` Label string `xml:"label,attr,omitempty"`
Label string `xml:"label,attr,omitempty"`
} }
// NewCategory creates a new Category. It returns a *Category and an error. // NewCategory creates a new Category. It returns a *Category and an error.
func NewCategory(term, content string) (*Category, error) { func NewCategory(term string) *Category {
if content != "" { return &Category{Term: term}
if !isValidXML(content) {
return nil, fmt.Errorf("%v not valid XML", content)
}
}
return &Category{Term: term, Content: content}, nil
} }
// SetLabel sets the label of the Category. // 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) 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 return nil
} }

17
link.go
View File

@ -9,7 +9,6 @@ import (
type Link struct { type Link struct {
*CommonAttributes *CommonAttributes
Title string `xml:"title,attr,omitempty"` Title string `xml:"title,attr,omitempty"`
Content string `xml:",chardata"` // 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"`
Type MediaType `xml:"type,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. // NewLink creates a new Link. It returns a *Link and an error.
func NewLink(href, content string) (*Link, error) { func NewLink(href, content string) *Link {
if content != "" { return &Link{Href: IRI(href)}
if !isValidXML(content) {
return nil, fmt.Errorf("%v not valid XML", content)
}
}
return &Link{Href: IRI(href), Content: content}, nil
} }
// Check checks the Link for incompatibilities with RFC4287. It returns an // 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 return nil
} }