1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-11 17:51:01 +00:00

refactor(misc): fix a handful of TODO

This commit is contained in:
jvoisin 2025-08-08 22:14:22 +02:00 committed by Frédéric Guillot
parent 06cbf1b3b3
commit 485baf9654
9 changed files with 18 additions and 27 deletions

View file

@ -18,11 +18,6 @@ type atom03Adapter struct {
atomFeed *atom03Feed
}
// TODO No need for a constructor, as it's only used in this package
func NewAtom03Adapter(atomFeed *atom03Feed) *atom03Adapter {
return &atom03Adapter{atomFeed}
}
func (a *atom03Adapter) buildFeed(baseURL string) *model.Feed {
feed := new(model.Feed)

View file

@ -18,15 +18,15 @@ import (
"miniflux.app/v2/internal/urllib"
)
type Atom10Adapter struct {
type atom10Adapter struct {
atomFeed *atom10Feed
}
func NewAtom10Adapter(atomFeed *atom10Feed) *Atom10Adapter {
return &Atom10Adapter{atomFeed}
func NewAtom10Adapter(atomFeed *atom10Feed) *atom10Adapter {
return &atom10Adapter{atomFeed}
}
func (a *Atom10Adapter) BuildFeed(baseURL string) *model.Feed {
func (a *atom10Adapter) BuildFeed(baseURL string) *model.Feed {
feed := new(model.Feed)
// Populate the feed URL.
@ -72,7 +72,7 @@ func (a *Atom10Adapter) BuildFeed(baseURL string) *model.Feed {
return feed
}
func (a *Atom10Adapter) populateEntries(siteURL string) model.Entries {
func (a *atom10Adapter) populateEntries(siteURL string) model.Entries {
entries := make(model.Entries, 0, len(a.atomFeed.Entries))
for _, atomEntry := range a.atomFeed.Entries {

View file

@ -19,12 +19,14 @@ func Parse(baseURL string, r io.ReadSeeker, version string) (*model.Feed, error)
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
return nil, fmt.Errorf("atom: unable to parse Atom 0.3 feed: %w", err)
}
return NewAtom03Adapter(atomFeed).buildFeed(baseURL), nil
adapter := &atom03Adapter{atomFeed}
return adapter.buildFeed(baseURL), nil
default:
atomFeed := new(atom10Feed)
if err := xml_decoder.NewXMLDecoder(r).Decode(atomFeed); err != nil {
return nil, fmt.Errorf("atom: unable to parse Atom 1.0 feed: %w", err)
}
return NewAtom10Adapter(atomFeed).BuildFeed(baseURL), nil
adapter := &atom10Adapter{atomFeed}
return adapter.BuildFeed(baseURL), nil
}
}

View file

@ -16,11 +16,6 @@ type opmlDocument struct {
Outlines opmlOutlineCollection `xml:"body>outline"`
}
// TODO remove as this is only used in the opml package
func NewOPMLDocument() *opmlDocument {
return &opmlDocument{}
}
type opmlHeader struct {
Title string `xml:"title,omitempty"`
DateCreated string `xml:"dateCreated,omitempty"`

View file

@ -13,7 +13,7 @@ import (
// parse reads an OPML file and returns a SubcriptionList.
func parse(data io.Reader) (subcriptionList, error) {
opmlDocument := NewOPMLDocument()
opmlDocument := &opmlDocument{}
decoder := xml.NewDecoder(data)
decoder.Entity = xml.HTMLEntity
decoder.Strict = false

View file

@ -32,7 +32,7 @@ func serialize(subscriptions subcriptionList) string {
}
func convertSubscriptionsToOPML(subscriptions subcriptionList) *opmlDocument {
opmlDocument := NewOPMLDocument()
opmlDocument := &opmlDocument{}
opmlDocument.Version = "2.0"
opmlDocument.Header.Title = "Miniflux"
opmlDocument.Header.DateCreated = time.Now().Format("Mon, 02 Jan 2006 15:04:05 MST")

View file

@ -197,13 +197,6 @@ type SanitizerOptions struct {
OpenLinksInNewTab bool
}
// TODO: replace with SanitizeHTML, as it's only used in tests.
func sanitizeHTMLWithDefaultOptions(baseURL, rawHTML string) string {
return SanitizeHTML(baseURL, rawHTML, &SanitizerOptions{
OpenLinksInNewTab: true,
})
}
func SanitizeHTML(baseURL, rawHTML string, sanitizerOptions *SanitizerOptions) string {
var tagStack []string
var parentTag string

View file

@ -13,6 +13,12 @@ import (
"miniflux.app/v2/internal/config"
)
func sanitizeHTMLWithDefaultOptions(baseURL, rawHTML string) string {
return SanitizeHTML(baseURL, rawHTML, &SanitizerOptions{
OpenLinksInNewTab: true,
})
}
func BenchmarkSanitize(b *testing.B) {
var testCases = map[string][]string{
"miniflux_github.html": {"https://github.com/miniflux/v2", ""},

View file

@ -88,7 +88,7 @@ func filterValidXMLChar(r rune) rune {
// This function is copied from encoding/xml's procInst and adapted for []bytes instead of string
func getEncoding(b []byte) string {
// TODO: this parsing is somewhat lame and not exact.
// This parsing is somewhat lame and not exact.
// It works for all actual cases, though.
idx := bytes.Index(b, []byte("encoding="))
if idx == -1 {