From 566227773ed5a67ff904df5af45b873014de6f6a Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Wed, 16 Oct 2024 16:58:58 +0200 Subject: [PATCH] Create NewGenerator and checks for the generator construct --- generator.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/generator.go b/generator.go index 4a67122..6867b58 100644 --- a/generator.go +++ b/generator.go @@ -1,6 +1,10 @@ package atomfeed -import "errors" +import ( + "errors" + "fmt" + "html" +) type Generator struct { *CommonAttributes @@ -9,10 +13,24 @@ type Generator struct { Text string `xml:"text"` } +func NewGenerator(text string) *Generator { + return &Generator{Text: html.UnescapeString(text)} +} + func (g *Generator) Check() error { + if g.URI != "" { + if !isValidURI(g.URI) { + return fmt.Errorf("uri attribute %v of generator not correctly formatted", g.URI) + } + } + if g.Text == "" { return errors.New("text element of generator empty") } + if !isCorrectlyEscaped(g.Text) { + return fmt.Errorf("text element %v of generator not correctly escaped", g.Text) + } + return nil }