From c7484c43bd7788ca23e975db2fd66a20e6a772a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20=27Necoro=27=20Neumann?= Date: Wed, 5 Aug 2020 22:32:06 +0200 Subject: [PATCH] #151: Add atom namespaces to known namespaces --- internal/shared/extparser.go | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/shared/extparser.go b/internal/shared/extparser.go index cb522b1e..f3cdb7ba 100644 --- a/internal/shared/extparser.go +++ b/internal/shared/extparser.go @@ -1,19 +1,33 @@ package shared import ( + "slices" "strings" - "github.com/mmcdole/gofeed/extensions" - "github.com/mmcdole/goxpp" + ext "github.com/mmcdole/gofeed/extensions" + xpp "github.com/mmcdole/goxpp" ) +var knownPrefixes = []string{ + "rss", + "rdf", + "content", + "atom", + "atom03", +} + // IsExtension returns whether or not the current // XML element is an extension element (if it has a // non empty prefix) func IsExtension(p *xpp.XMLPullParser) bool { space := strings.TrimSpace(p.Space) prefix := PrefixForNamespace(space, p) - return !(prefix == "" || prefix == "rss" || prefix == "rdf" || prefix == "content") + + if prefix == "" { + return false + } + + return !slices.Contains(knownPrefixes, prefix) } // ParseExtension parses the current element of the @@ -118,6 +132,8 @@ func PrefixForNamespace(space string, p *xpp.XMLPullParser) string { // These canonical prefixes override any prefixes used in the feed itself. var canonicalNamespaces = map[string]string{ "http://webns.net/mvcb/": "admin", + "http://www.w3.org/2005/Atom": "atom", + "http://purl.org/atom/ns#": "atom03", "http://purl.org/rss/1.0/modules/aggregation/": "ag", "http://purl.org/rss/1.0/modules/annotate/": "annotate", "http://media.tangent.org/rss/1.0/": "audio",