Correctly escape strings if needed and check for it

This commit is contained in:
2024-10-16 16:51:39 +02:00
parent c200d5bf73
commit f27116930a
4 changed files with 26 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ package atomfeed
import (
"errors"
"fmt"
"html"
)
type Category struct {
@@ -22,6 +23,10 @@ func NewCategory(term string) (*Category, error) {
return &Category{Term: term, Content: content}, nil
}
func (c *Category) SetLabel(label string) {
c.Label = html.UnescapeString(label)
}
func (c *Category) Check() error {
if c.Term == "" {
return errors.New("term attribute of category empty")
@@ -33,6 +38,10 @@ func (c *Category) Check() error {
}
}
if !isCorrectlyEscaped(c.Label) {
return fmt.Errorf("label attribute of category %v not correctly escaped", c.Label)
}
if c.Content == nil {
return errors.New("no content element of category")
} else {