Skip to content

Commit

Permalink
mmcdole#151: Add atom namespaces to known namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Necoro committed Jul 10, 2024
1 parent 9455e2b commit 4438381
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.0.1 // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37
gopkg.in/yaml.v3 v3.0.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKs
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/urfave/cli v1.22.3 h1:FpNT6zq26xNpHZy08emi755QwzLPs6Pukqjlc7RfOMU=
github.com/urfave/cli v1.22.3/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 h1:uLDX+AfeFCct3a2C7uIWBKMJIR3CJMhcgfrUAqjRK6w=
golang.org/x/exp v0.0.0-20240707233637-46b078467d37/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
Expand Down
22 changes: 19 additions & 3 deletions internal/shared/extparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,31 @@ package shared
import (
"strings"

"github.com/mmcdole/gofeed/extensions"
"github.com/mmcdole/goxpp"
ext "github.com/mmcdole/gofeed/extensions"
xpp "github.com/mmcdole/goxpp"
"golang.org/x/exp/slices"
)

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
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 4438381

Please sign in to comment.