Correctly escape strings if needed and check for it
This commit is contained in:
@@ -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 {
|
||||
|
Reference in New Issue
Block a user