Compare commits
No commits in common. "987feb822615886361262a7bb1bf811a1f821470" and "b08b62e7946b71a18409ca801effacea168cca12" have entirely different histories.
987feb8226
...
b08b62e794
23
atom.go
23
atom.go
@ -1,31 +1,8 @@
|
|||||||
package atomfeed
|
package atomfeed
|
||||||
|
|
||||||
import (
|
|
||||||
"mime"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
EmailAddress string
|
EmailAddress string
|
||||||
LanguageTag string
|
LanguageTag string
|
||||||
MediaType string
|
MediaType string
|
||||||
URI string
|
URI string
|
||||||
)
|
)
|
||||||
|
|
||||||
func isCompositeMediaType(mediaType string) bool {
|
|
||||||
mediaType, _, err := mime.ParseMediaType(mediaType)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.HasPrefix(mediaType, "multipart/") || strings.HasPrefix(mediaType, "message/")
|
|
||||||
}
|
|
||||||
|
|
||||||
func isXMLMediaType(mediaType string) bool {
|
|
||||||
mediaType, _, err := mime.ParseMediaType(mediaType)
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.HasSuffix(mediaType, "/xml") || strings.HasSuffix(mediaType, "+xml")
|
|
||||||
}
|
|
||||||
|
10
entry.go
10
entry.go
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"mime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,6 +59,10 @@ func alternateRelExists(l []*Link) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isXMLMediaType(mediaType string) bool {
|
||||||
|
return strings.HasSuffix(mediaType, "/xml") || strings.HasSuffix(mediaType, "+xml")
|
||||||
|
}
|
||||||
|
|
||||||
func (e *Entry) AddExtension(name string, value any) {
|
func (e *Entry) AddExtension(name string, value any) {
|
||||||
e.Extensions = append(e.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value})
|
e.Extensions = append(e.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value})
|
||||||
}
|
}
|
||||||
@ -143,7 +148,10 @@ func (e *Entry) Check() error {
|
|||||||
// "type" attribute of atom:content is a MIME media type [MIMEREG], but
|
// "type" attribute of atom:content is a MIME media type [MIMEREG], but
|
||||||
// is not an XML media type [RFC3023], does not begin with "text/", and
|
// is not an XML media type [RFC3023], does not begin with "text/", and
|
||||||
// does not end with "/xml" or "+xml".
|
// does not end with "/xml" or "+xml".
|
||||||
mediaType := e.Content.getType()
|
mediaType, _, err := mime.ParseMediaType(e.Content.getType())
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("type attribute of content element of entry %v: %v", e.ID.URI, err)
|
||||||
|
}
|
||||||
if !isXMLMediaType(mediaType) && !strings.HasPrefix(mediaType, "text/") {
|
if !isXMLMediaType(mediaType) && !strings.HasPrefix(mediaType, "text/") {
|
||||||
return fmt.Errorf("no summary element of entry %v but media type not xml", e.ID.URI)
|
return fmt.Errorf("no summary element of entry %v but media type not xml", e.ID.URI)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package atomfeed
|
package atomfeed
|
||||||
|
|
||||||
import "errors"
|
|
||||||
|
|
||||||
type InlineOtherContent struct {
|
type InlineOtherContent struct {
|
||||||
*CommonAttributes
|
*CommonAttributes
|
||||||
Type MediaType `xml:"type,attr,omitempty"`
|
Type MediaType `xml:"type,attr,omitempty"`
|
||||||
@ -14,10 +12,4 @@ func (i *InlineOtherContent) hasSRC() bool { return false }
|
|||||||
|
|
||||||
func (i *InlineOtherContent) getType() string { return string(i.Type) }
|
func (i *InlineOtherContent) getType() string { return string(i.Type) }
|
||||||
|
|
||||||
func (i *InlineOtherContent) Check() error {
|
func (i *InlineOtherContent) Check() error { return nil }
|
||||||
if isCompositeMediaType(i.getType()) {
|
|
||||||
return errors.New("type attribute of inline other content must not be a composite type")
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
@ -15,10 +15,6 @@ func (o *OutOfLineContent) hasSRC() bool { return true }
|
|||||||
func (o *OutOfLineContent) getType() string { return string(o.Type) }
|
func (o *OutOfLineContent) getType() string { return string(o.Type) }
|
||||||
|
|
||||||
func (o *OutOfLineContent) Check() error {
|
func (o *OutOfLineContent) Check() error {
|
||||||
if isCompositeMediaType(o.getType()) {
|
|
||||||
return errors.New("type attribute of out of line content must not be a composite type")
|
|
||||||
}
|
|
||||||
|
|
||||||
if o.SRC == "" {
|
if o.SRC == "" {
|
||||||
return errors.New("src attribute of out of line content empty")
|
return errors.New("src attribute of out of line content empty")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user