Compare commits
	
		
			4 Commits
		
	
	
		
			b08b62e794
			...
			987feb8226
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 987feb8226 | |||
| 6322566a54 | |||
| 209059f2b4 | |||
| e3b9ff0225 | 
							
								
								
									
										23
									
								
								atom.go
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								atom.go
									
									
									
									
									
								
							@@ -1,8 +1,31 @@
 | 
			
		||||
package atomfeed
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"mime"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type (
 | 
			
		||||
	EmailAddress string
 | 
			
		||||
	LanguageTag  string
 | 
			
		||||
	MediaType    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,7 +4,6 @@ import (
 | 
			
		||||
	"encoding/xml"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"mime"
 | 
			
		||||
	"strings"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@@ -59,10 +58,6 @@ func alternateRelExists(l []*Link) bool {
 | 
			
		||||
	return false
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func isXMLMediaType(mediaType string) bool {
 | 
			
		||||
	return strings.HasSuffix(mediaType, "/xml") || strings.HasSuffix(mediaType, "+xml")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (e *Entry) AddExtension(name string, value any) {
 | 
			
		||||
	e.Extensions = append(e.Extensions, &ExtensionElement{XMLName: xml.Name{Local: name}, Value: value})
 | 
			
		||||
}
 | 
			
		||||
@@ -148,10 +143,7 @@ func (e *Entry) Check() error {
 | 
			
		||||
		// "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
 | 
			
		||||
		// does not end with "/xml" or "+xml".
 | 
			
		||||
		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)
 | 
			
		||||
		}
 | 
			
		||||
		mediaType := e.Content.getType()
 | 
			
		||||
		if !isXMLMediaType(mediaType) && !strings.HasPrefix(mediaType, "text/") {
 | 
			
		||||
			return fmt.Errorf("no summary element of entry %v but media type not xml", e.ID.URI)
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
package atomfeed
 | 
			
		||||
 | 
			
		||||
import "errors"
 | 
			
		||||
 | 
			
		||||
type InlineOtherContent struct {
 | 
			
		||||
	*CommonAttributes
 | 
			
		||||
	Type       MediaType `xml:"type,attr,omitempty"`
 | 
			
		||||
@@ -12,4 +14,10 @@ func (i *InlineOtherContent) hasSRC() bool { return false }
 | 
			
		||||
 | 
			
		||||
func (i *InlineOtherContent) getType() string { return string(i.Type) }
 | 
			
		||||
 | 
			
		||||
func (i *InlineOtherContent) Check() error { return nil }
 | 
			
		||||
func (i *InlineOtherContent) Check() error {
 | 
			
		||||
	if isCompositeMediaType(i.getType()) {
 | 
			
		||||
		return errors.New("type attribute of inline other content must not be a composite type")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -15,6 +15,10 @@ func (o *OutOfLineContent) hasSRC() bool { return true }
 | 
			
		||||
func (o *OutOfLineContent) getType() string { return string(o.Type) }
 | 
			
		||||
 | 
			
		||||
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 == "" {
 | 
			
		||||
		return errors.New("src attribute of out of line content empty")
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user