Compare commits
2 Commits
73624eadd8
...
e73b78ef30
Author | SHA1 | Date | |
---|---|---|---|
e73b78ef30 | |||
5a82f1799f |
7
atom.go
7
atom.go
@ -1,6 +1,7 @@
|
||||
package atom
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"mime"
|
||||
"regexp"
|
||||
@ -86,3 +87,9 @@ func isValidLanguageTag(tag LanguageTag) bool {
|
||||
func NewURN() IRI {
|
||||
return IRI(fmt.Sprint("urn:uuid:", uuid.New()))
|
||||
}
|
||||
|
||||
// isValidXML checks whether a string is valid XML. It returns a bool.
|
||||
func isValidXML(input string) bool {
|
||||
var v interface{}
|
||||
return xml.Unmarshal([]byte(input), &v) == nil
|
||||
}
|
||||
|
12
category.go
12
category.go
@ -16,6 +16,12 @@ type Category struct {
|
||||
|
||||
// NewCategory creates a new Category. It returns a *Category and an error.
|
||||
func NewCategory(term, content string) (*Category, error) {
|
||||
if content != "" {
|
||||
if !isValidXML(content) {
|
||||
return nil, fmt.Errorf("%v not valid XML", content)
|
||||
}
|
||||
}
|
||||
|
||||
return &Category{Term: term, Content: content}, nil
|
||||
}
|
||||
|
||||
@ -41,8 +47,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
|
||||
|
12
link.go
12
link.go
@ -19,6 +19,12 @@ type Link struct {
|
||||
|
||||
// NewLink creates a new Link. It returns a *Link and an error.
|
||||
func NewLink(href, content string) (*Link, error) {
|
||||
if content != "" {
|
||||
if !isValidXML(content) {
|
||||
return nil, fmt.Errorf("%v not valid XML", content)
|
||||
}
|
||||
}
|
||||
|
||||
return &Link{Href: IRI(href), Content: content}, nil
|
||||
}
|
||||
|
||||
@ -51,8 +57,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
|
||||
|
Loading…
x
Reference in New Issue
Block a user