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

View File

@@ -16,6 +16,10 @@ type Category struct {
// NewCategory creates a new Category. It returns a *Category and an error.
func NewCategory(term, content string) (*Category, error) {
if !isValidXML(content) {
return nil, fmt.Errorf("%v not valid XML", content)
}
return &Category{Term: term, Content: content}, nil
}
@@ -41,8 +45,10 @@ func (c *Category) Check() error {
return fmt.Errorf("label attribute %v of category not correctly escaped", c.Label)
}
if c.Content == "" {
return errors.New("content element of category empty")
if c.Content != "" {
if !isValidXML(c.Content) {
return fmt.Errorf("content element %v of category not valid XML", c.Content)
}
}
return nil