From 209059f2b477591eef0514212bb6653675e64133 Mon Sep 17 00:00:00 2001 From: Jason Streifling Date: Tue, 15 Oct 2024 19:46:26 +0200 Subject: [PATCH] Move the parsing of the media type to isXMLMediaType --- atom.go | 10 +++++++++- entry.go | 6 +----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/atom.go b/atom.go index a8f16bd..d3c7a5b 100644 --- a/atom.go +++ b/atom.go @@ -1,6 +1,9 @@ package atomfeed -import "strings" +import ( + "mime" + "strings" +) type ( EmailAddress string @@ -10,5 +13,10 @@ type ( ) func isXMLMediaType(mediaType string) bool { + mediaType, _, err := mime.ParseMediaType(mediaType) + if err != nil { + return false + } + return strings.HasSuffix(mediaType, "/xml") || strings.HasSuffix(mediaType, "+xml") } diff --git a/entry.go b/entry.go index 0cac599..e4d16f9 100644 --- a/entry.go +++ b/entry.go @@ -4,7 +4,6 @@ import ( "encoding/xml" "errors" "fmt" - "mime" "strings" ) @@ -144,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) }