Force undefined content of category and link to be empty or valid xml

This commit is contained in:
2024-10-17 18:39:57 +02:00
parent 73624eadd8
commit 5a82f1799f
3 changed files with 23 additions and 4 deletions

10
link.go
View File

@@ -19,6 +19,10 @@ type Link struct {
// NewLink creates a new Link. It returns a *Link and an error.
func NewLink(href, content string) (*Link, error) {
if !isValidXML(content) {
return nil, fmt.Errorf("%v not valid XML", content)
}
return &Link{Href: IRI(href), Content: content}, nil
}
@@ -51,8 +55,10 @@ func (l *Link) Check() error {
}
}
if l.Content == "" {
return errors.New("content element of link empty")
if l.Content != "" {
if !isValidXML(l.Content) {
return fmt.Errorf("content element %v of link not valid XML", l.Content)
}
}
return nil