From e5d9f2f5a05453043ed29c79f3f1a8865f26d99d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Guillot?= Date: Sun, 13 Aug 2023 19:09:01 -0700 Subject: [PATCH] Rename internal url package to avoid overlap with net/url --- internal/api/entry.go | 4 ++-- internal/googlereader/handler.go | 4 ++-- internal/integration/apprise/apprise.go | 4 ++-- internal/integration/espial/espial.go | 4 ++-- internal/integration/linkding/linkding.go | 4 ++-- internal/integration/nunuxkeeper/nunuxkeeper.go | 4 ++-- internal/integration/shaarli/shaarli.go | 4 ++-- internal/integration/shiori/shiori.go | 6 +++--- internal/integration/wallabag/wallabag.go | 6 +++--- internal/proxy/media_proxy.go | 14 +++++++------- internal/reader/atom/atom_03.go | 8 ++++---- internal/reader/atom/atom_10.go | 10 +++++----- internal/reader/icon/finder.go | 13 ++++++------- internal/reader/json/json.go | 8 ++++---- internal/reader/rdf/rdf.go | 6 +++--- internal/reader/rewrite/rewriter.go | 4 ++-- internal/reader/rss/rss.go | 10 +++++----- internal/reader/sanitizer/sanitizer.go | 10 +++++----- internal/reader/scraper/scraper.go | 6 +++--- internal/reader/subscription/finder.go | 10 +++++----- internal/template/functions.go | 6 +++--- internal/{url => urllib}/url.go | 2 +- internal/{url => urllib}/url_test.go | 2 +- 23 files changed, 74 insertions(+), 75 deletions(-) rename internal/{url => urllib}/url.go (97%) rename internal/{url => urllib}/url_test.go (98%) diff --git a/internal/api/entry.go b/internal/api/entry.go index e06482a4..1044e849 100644 --- a/internal/api/entry.go +++ b/internal/api/entry.go @@ -19,7 +19,7 @@ import ( "miniflux.app/v2/internal/proxy" "miniflux.app/v2/internal/reader/processor" "miniflux.app/v2/internal/storage" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "miniflux.app/v2/internal/validator" ) @@ -39,7 +39,7 @@ func (h *handler) getEntryFromBuilder(w http.ResponseWriter, r *http.Request, b proxyOption := config.Opts.ProxyOption() for i := range entry.Enclosures { - if proxyOption == "all" || proxyOption != "none" && !url.IsHTTPS(entry.Enclosures[i].URL) { + if proxyOption == "all" || proxyOption != "none" && !urllib.IsHTTPS(entry.Enclosures[i].URL) { for _, mediaType := range config.Opts.ProxyMediaTypes() { if strings.HasPrefix(entry.Enclosures[i].MimeType, mediaType+"/") { entry.Enclosures[i].URL = proxy.AbsoluteProxifyURL(h.router, r.Host, entry.Enclosures[i].URL) diff --git a/internal/googlereader/handler.go b/internal/googlereader/handler.go index 9ed7f820..214fd884 100644 --- a/internal/googlereader/handler.go +++ b/internal/googlereader/handler.go @@ -24,7 +24,7 @@ import ( mff "miniflux.app/v2/internal/reader/handler" mfs "miniflux.app/v2/internal/reader/subscription" "miniflux.app/v2/internal/storage" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "miniflux.app/v2/internal/validator" ) @@ -843,7 +843,7 @@ func (h *handler) streamItemContents(w http.ResponseWriter, r *http.Request) { proxyOption := config.Opts.ProxyOption() for i := range entry.Enclosures { - if proxyOption == "all" || proxyOption != "none" && !url.IsHTTPS(entry.Enclosures[i].URL) { + if proxyOption == "all" || proxyOption != "none" && !urllib.IsHTTPS(entry.Enclosures[i].URL) { for _, mediaType := range config.Opts.ProxyMediaTypes() { if strings.HasPrefix(entry.Enclosures[i].MimeType, mediaType+"/") { entry.Enclosures[i].URL = proxy.AbsoluteProxifyURL(h.router, r.Host, entry.Enclosures[i].URL) diff --git a/internal/integration/apprise/apprise.go b/internal/integration/apprise/apprise.go index 89ea3b6e..3d1c40a2 100644 --- a/internal/integration/apprise/apprise.go +++ b/internal/integration/apprise/apprise.go @@ -11,7 +11,7 @@ import ( "miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/model" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) const defaultClientTimeout = 1 * time.Second @@ -34,7 +34,7 @@ func (c *Client) PushEntry(entry *model.Entry) error { } _, err := net.DialTimeout("tcp", c.baseURL, defaultClientTimeout) if err != nil { - apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/notify") + apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/notify") if err != nil { return fmt.Errorf(`apprise: invalid API endpoint: %v`, err) } diff --git a/internal/integration/espial/espial.go b/internal/integration/espial/espial.go index 4751a880..b7a9cc70 100644 --- a/internal/integration/espial/espial.go +++ b/internal/integration/espial/espial.go @@ -7,7 +7,7 @@ import ( "fmt" "miniflux.app/v2/internal/http/client" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) // Document structure of an Espial document @@ -42,7 +42,7 @@ func (c *Client) AddEntry(link, title, content, tags string) error { Tags: tags, } - apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/api/add") + apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/add") if err != nil { return fmt.Errorf(`espial: invalid API endpoint: %v`, err) } diff --git a/internal/integration/linkding/linkding.go b/internal/integration/linkding/linkding.go index 8fa98602..9cbd3cc5 100644 --- a/internal/integration/linkding/linkding.go +++ b/internal/integration/linkding/linkding.go @@ -8,7 +8,7 @@ import ( "strings" "miniflux.app/v2/internal/http/client" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) // Document structure of a Linkding document @@ -49,7 +49,7 @@ func (c *Client) AddEntry(title, entryURL string) error { Unread: c.unread, } - apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/api/bookmarks/") + apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/bookmarks/") if err != nil { return fmt.Errorf(`linkding: invalid API endpoint: %v`, err) } diff --git a/internal/integration/nunuxkeeper/nunuxkeeper.go b/internal/integration/nunuxkeeper/nunuxkeeper.go index b734cc98..7c8d4d78 100644 --- a/internal/integration/nunuxkeeper/nunuxkeeper.go +++ b/internal/integration/nunuxkeeper/nunuxkeeper.go @@ -7,7 +7,7 @@ import ( "fmt" "miniflux.app/v2/internal/http/client" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) // Document structure of a Nununx Keeper document @@ -42,7 +42,7 @@ func (c *Client) AddEntry(link, title, content string) error { ContentType: "text/html", } - apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/v2/documents") + apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/v2/documents") if err != nil { return fmt.Errorf(`nunux-keeper: invalid API endpoint: %v`, err) } diff --git a/internal/integration/shaarli/shaarli.go b/internal/integration/shaarli/shaarli.go index d88e3cf4..e5d49fd0 100644 --- a/internal/integration/shaarli/shaarli.go +++ b/internal/integration/shaarli/shaarli.go @@ -14,7 +14,7 @@ import ( "strings" "time" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "miniflux.app/v2/internal/version" ) @@ -34,7 +34,7 @@ func (c *Client) AddLink(entryURL, entryTitle string) error { return fmt.Errorf("shaarli: missing base URL or API secret") } - apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/api/v1/links") + apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/v1/links") if err != nil { return fmt.Errorf("shaarli: invalid API endpoint: %v", err) } diff --git a/internal/integration/shiori/shiori.go b/internal/integration/shiori/shiori.go index c55a530d..455aaebe 100644 --- a/internal/integration/shiori/shiori.go +++ b/internal/integration/shiori/shiori.go @@ -10,7 +10,7 @@ import ( "net/http" "time" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "miniflux.app/v2/internal/version" ) @@ -36,7 +36,7 @@ func (c *Client) AddBookmark(entryURL, entryTitle string) error { return fmt.Errorf("shiori: unable to authenticate: %v", err) } - apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/api/bookmarks") + apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/bookmarks") if err != nil { return fmt.Errorf("shiori: invalid API endpoint: %v", err) } @@ -77,7 +77,7 @@ func (c *Client) AddBookmark(entryURL, entryTitle string) error { } func (c *Client) authenticate() (sessionID string, err error) { - apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/api/login") + apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/login") if err != nil { return "", fmt.Errorf("shiori: invalid API endpoint: %v", err) } diff --git a/internal/integration/wallabag/wallabag.go b/internal/integration/wallabag/wallabag.go index b8044445..e5788185 100644 --- a/internal/integration/wallabag/wallabag.go +++ b/internal/integration/wallabag/wallabag.go @@ -10,7 +10,7 @@ import ( "net/url" "miniflux.app/v2/internal/http/client" - internal_url "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) // Client represents a Wallabag client. @@ -44,7 +44,7 @@ func (c *Client) AddEntry(link, title, content string) error { } func (c *Client) createEntry(accessToken, link, title, content string) error { - endpoint, err := internal_url.JoinBaseURLAndPath(c.baseURL, "/api/entries.json") + endpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/entries.json") if err != nil { return fmt.Errorf("wallbag: unable to generate entries endpoint: %v", err) } @@ -76,7 +76,7 @@ func (c *Client) getAccessToken() (string, error) { values.Add("username", c.username) values.Add("password", c.password) - endpoint, err := internal_url.JoinBaseURLAndPath(c.baseURL, "/oauth/v2/token") + endpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/oauth/v2/token") if err != nil { return "", fmt.Errorf("wallbag: unable to generate token endpoint: %v", err) } diff --git a/internal/proxy/media_proxy.go b/internal/proxy/media_proxy.go index 6fc7a92e..14de7d7e 100644 --- a/internal/proxy/media_proxy.go +++ b/internal/proxy/media_proxy.go @@ -8,7 +8,7 @@ import ( "miniflux.app/v2/internal/config" "miniflux.app/v2/internal/reader/sanitizer" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "github.com/PuerkitoBio/goquery" "github.com/gorilla/mux" @@ -45,7 +45,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, case "image": doc.Find("img").Each(func(i int, img *goquery.Selection) { if srcAttrValue, ok := img.Attr("src"); ok { - if !isDataURL(srcAttrValue) && (proxyOption == "all" || !url.IsHTTPS(srcAttrValue)) { + if !isDataURL(srcAttrValue) && (proxyOption == "all" || !urllib.IsHTTPS(srcAttrValue)) { img.SetAttr("src", proxifyFunction(router, srcAttrValue)) } } @@ -64,7 +64,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, case "audio": doc.Find("audio").Each(func(i int, audio *goquery.Selection) { if srcAttrValue, ok := audio.Attr("src"); ok { - if !isDataURL(srcAttrValue) && (proxyOption == "all" || !url.IsHTTPS(srcAttrValue)) { + if !isDataURL(srcAttrValue) && (proxyOption == "all" || !urllib.IsHTTPS(srcAttrValue)) { audio.SetAttr("src", proxifyFunction(router, srcAttrValue)) } } @@ -72,7 +72,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, doc.Find("audio source").Each(func(i int, sourceElement *goquery.Selection) { if srcAttrValue, ok := sourceElement.Attr("src"); ok { - if !isDataURL(srcAttrValue) && (proxyOption == "all" || !url.IsHTTPS(srcAttrValue)) { + if !isDataURL(srcAttrValue) && (proxyOption == "all" || !urllib.IsHTTPS(srcAttrValue)) { sourceElement.SetAttr("src", proxifyFunction(router, srcAttrValue)) } } @@ -81,7 +81,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, case "video": doc.Find("video").Each(func(i int, video *goquery.Selection) { if srcAttrValue, ok := video.Attr("src"); ok { - if !isDataURL(srcAttrValue) && (proxyOption == "all" || !url.IsHTTPS(srcAttrValue)) { + if !isDataURL(srcAttrValue) && (proxyOption == "all" || !urllib.IsHTTPS(srcAttrValue)) { video.SetAttr("src", proxifyFunction(router, srcAttrValue)) } } @@ -89,7 +89,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter, doc.Find("video source").Each(func(i int, sourceElement *goquery.Selection) { if srcAttrValue, ok := sourceElement.Attr("src"); ok { - if !isDataURL(srcAttrValue) && (proxyOption == "all" || !url.IsHTTPS(srcAttrValue)) { + if !isDataURL(srcAttrValue) && (proxyOption == "all" || !urllib.IsHTTPS(srcAttrValue)) { sourceElement.SetAttr("src", proxifyFunction(router, srcAttrValue)) } } @@ -109,7 +109,7 @@ func proxifySourceSet(element *goquery.Selection, router *mux.Router, proxifyFun imageCandidates := sanitizer.ParseSrcSetAttribute(srcsetAttrValue) for _, imageCandidate := range imageCandidates { - if !isDataURL(imageCandidate.ImageURL) && (proxyOption == "all" || !url.IsHTTPS(imageCandidate.ImageURL)) { + if !isDataURL(imageCandidate.ImageURL) && (proxyOption == "all" || !urllib.IsHTTPS(imageCandidate.ImageURL)) { imageCandidate.ImageURL = proxifyFunction(router, imageCandidate.ImageURL) } } diff --git a/internal/reader/atom/atom_03.go b/internal/reader/atom/atom_03.go index abf07a29..a760ce26 100644 --- a/internal/reader/atom/atom_03.go +++ b/internal/reader/atom/atom_03.go @@ -14,7 +14,7 @@ import ( "miniflux.app/v2/internal/model" "miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/sanitizer" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) // Specs: http://web.archive.org/web/20060811235523/http://www.mnot.net/drafts/draft-nottingham-atom-format-02.html @@ -32,13 +32,13 @@ func (a *atom03Feed) Transform(baseURL string) *model.Feed { feed := new(model.Feed) feedURL := a.Links.firstLinkWithRelation("self") - feed.FeedURL, err = url.AbsoluteURL(baseURL, feedURL) + feed.FeedURL, err = urllib.AbsoluteURL(baseURL, feedURL) if err != nil { feed.FeedURL = feedURL } siteURL := a.Links.originalLink() - feed.SiteURL, err = url.AbsoluteURL(baseURL, siteURL) + feed.SiteURL, err = urllib.AbsoluteURL(baseURL, siteURL) if err != nil { feed.SiteURL = siteURL } @@ -50,7 +50,7 @@ func (a *atom03Feed) Transform(baseURL string) *model.Feed { for _, entry := range a.Entries { item := entry.Transform() - entryURL, err := url.AbsoluteURL(feed.SiteURL, item.URL) + entryURL, err := urllib.AbsoluteURL(feed.SiteURL, item.URL) if err == nil { item.URL = entryURL } diff --git a/internal/reader/atom/atom_10.go b/internal/reader/atom/atom_10.go index 4b0d0dfe..2c6edf17 100644 --- a/internal/reader/atom/atom_10.go +++ b/internal/reader/atom/atom_10.go @@ -16,7 +16,7 @@ import ( "miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/media" "miniflux.app/v2/internal/reader/sanitizer" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) // Specs: @@ -38,13 +38,13 @@ func (a *atom10Feed) Transform(baseURL string) *model.Feed { feed := new(model.Feed) feedURL := a.Links.firstLinkWithRelation("self") - feed.FeedURL, err = url.AbsoluteURL(baseURL, feedURL) + feed.FeedURL, err = urllib.AbsoluteURL(baseURL, feedURL) if err != nil { feed.FeedURL = feedURL } siteURL := a.Links.originalLink() - feed.SiteURL, err = url.AbsoluteURL(baseURL, siteURL) + feed.SiteURL, err = urllib.AbsoluteURL(baseURL, siteURL) if err != nil { feed.SiteURL = siteURL } @@ -58,7 +58,7 @@ func (a *atom10Feed) Transform(baseURL string) *model.Feed { for _, entry := range a.Entries { item := entry.Transform() - entryURL, err := url.AbsoluteURL(feed.SiteURL, item.URL) + entryURL, err := urllib.AbsoluteURL(feed.SiteURL, item.URL) if err == nil { item.URL = entryURL } @@ -237,7 +237,7 @@ func (r *atom10Entry) entryCategories() []string { // We accept only HTML or XHTML documents for now since the intention is to have the same behavior as RSS. func (a *atom10Entry) entryCommentsURL() string { commentsURL := a.Links.firstLinkWithRelationAndType("replies", "text/html", "application/xhtml+xml") - if url.IsAbsoluteURL(commentsURL) { + if urllib.IsAbsoluteURL(commentsURL) { return commentsURL } return "" diff --git a/internal/reader/icon/finder.go b/internal/reader/icon/finder.go index 7f017979..bb412615 100644 --- a/internal/reader/icon/finder.go +++ b/internal/reader/icon/finder.go @@ -7,16 +7,15 @@ import ( "encoding/base64" "fmt" "io" + "net/url" "strings" - stdlib_url "net/url" - "miniflux.app/v2/internal/config" "miniflux.app/v2/internal/crypto" "miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/model" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "github.com/PuerkitoBio/goquery" ) @@ -24,7 +23,7 @@ import ( // FindIcon try to find the website's icon. func FindIcon(websiteURL, iconURL, userAgent string, fetchViaProxy, allowSelfSignedCertificates bool) (*model.Icon, error) { if iconURL == "" { - rootURL := url.RootURL(websiteURL) + rootURL := urllib.RootURL(websiteURL) logger.Debug("[FindIcon] Trying to find an icon: rootURL=%q websiteURL=%q userAgent=%q", rootURL, websiteURL, userAgent) clt := client.NewClientWithConfig(rootURL, config.Opts) @@ -90,9 +89,9 @@ func parseDocument(websiteURL string, data io.Reader) (string, error) { } if iconURL == "" { - iconURL = url.RootURL(websiteURL) + "favicon.ico" + iconURL = urllib.RootURL(websiteURL) + "favicon.ico" } else { - iconURL, _ = url.AbsoluteURL(websiteURL, iconURL) + iconURL, _ = urllib.AbsoluteURL(websiteURL, iconURL) } return iconURL, nil @@ -173,7 +172,7 @@ func parseImageDataURL(value string) (*model.Icon, error) { return nil, fmt.Errorf(`icon: invalid data %q (%v)`, value, err) } case "": - decodedData, err := stdlib_url.QueryUnescape(data) + decodedData, err := url.QueryUnescape(data) if err != nil { return nil, fmt.Errorf(`icon: unable to decode data URL %q`, value) } diff --git a/internal/reader/json/json.go b/internal/reader/json/json.go index 48879541..48f64c23 100644 --- a/internal/reader/json/json.go +++ b/internal/reader/json/json.go @@ -12,7 +12,7 @@ import ( "miniflux.app/v2/internal/model" "miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/sanitizer" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) type jsonFeed struct { @@ -67,12 +67,12 @@ func (j *jsonFeed) Transform(baseURL string) *model.Feed { feed := new(model.Feed) - feed.FeedURL, err = url.AbsoluteURL(baseURL, j.FeedURL) + feed.FeedURL, err = urllib.AbsoluteURL(baseURL, j.FeedURL) if err != nil { feed.FeedURL = j.FeedURL } - feed.SiteURL, err = url.AbsoluteURL(baseURL, j.SiteURL) + feed.SiteURL, err = urllib.AbsoluteURL(baseURL, j.SiteURL) if err != nil { feed.SiteURL = j.SiteURL } @@ -90,7 +90,7 @@ func (j *jsonFeed) Transform(baseURL string) *model.Feed { for _, item := range j.Items { entry := item.Transform() - entryURL, err := url.AbsoluteURL(feed.SiteURL, entry.URL) + entryURL, err := urllib.AbsoluteURL(feed.SiteURL, entry.URL) if err == nil { entry.URL = entryURL } diff --git a/internal/reader/rdf/rdf.go b/internal/reader/rdf/rdf.go index 5b0e649f..6118ec20 100644 --- a/internal/reader/rdf/rdf.go +++ b/internal/reader/rdf/rdf.go @@ -14,7 +14,7 @@ import ( "miniflux.app/v2/internal/model" "miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/sanitizer" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) type rdfFeed struct { @@ -30,7 +30,7 @@ func (r *rdfFeed) Transform(baseURL string) *model.Feed { feed := new(model.Feed) feed.Title = sanitizer.StripTags(r.Title) feed.FeedURL = baseURL - feed.SiteURL, err = url.AbsoluteURL(baseURL, r.Link) + feed.SiteURL, err = urllib.AbsoluteURL(baseURL, r.Link) if err != nil { feed.SiteURL = r.Link } @@ -44,7 +44,7 @@ func (r *rdfFeed) Transform(baseURL string) *model.Feed { if entry.URL == "" { entry.URL = feed.SiteURL } else { - entryURL, err := url.AbsoluteURL(feed.SiteURL, entry.URL) + entryURL, err := urllib.AbsoluteURL(feed.SiteURL, entry.URL) if err == nil { entry.URL = entryURL } diff --git a/internal/reader/rewrite/rewriter.go b/internal/reader/rewrite/rewriter.go index c761ef96..b5fb8ad7 100644 --- a/internal/reader/rewrite/rewriter.go +++ b/internal/reader/rewrite/rewriter.go @@ -10,7 +10,7 @@ import ( "miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/model" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) type rule struct { @@ -116,7 +116,7 @@ func applyRule(entryURL string, entry *model.Entry, rule rule) { } func getPredefinedRewriteRules(entryURL string) string { - urlDomain := url.Domain(entryURL) + urlDomain := urllib.Domain(entryURL) for domain, rules := range predefinedRules { if strings.Contains(urlDomain, domain) { return rules diff --git a/internal/reader/rss/rss.go b/internal/reader/rss/rss.go index 7edf91db..93584bf0 100644 --- a/internal/reader/rss/rss.go +++ b/internal/reader/rss/rss.go @@ -17,7 +17,7 @@ import ( "miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/media" "miniflux.app/v2/internal/reader/sanitizer" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" ) // Specs: https://cyber.harvard.edu/rss/rss.html @@ -42,13 +42,13 @@ func (r *rssFeed) Transform(baseURL string) *model.Feed { feed := new(model.Feed) siteURL := r.siteURL() - feed.SiteURL, err = url.AbsoluteURL(baseURL, siteURL) + feed.SiteURL, err = urllib.AbsoluteURL(baseURL, siteURL) if err != nil { feed.SiteURL = siteURL } feedURL := r.feedURL() - feed.FeedURL, err = url.AbsoluteURL(baseURL, feedURL) + feed.FeedURL, err = urllib.AbsoluteURL(baseURL, feedURL) if err != nil { feed.FeedURL = feedURL } @@ -69,7 +69,7 @@ func (r *rssFeed) Transform(baseURL string) *model.Feed { if entry.URL == "" { entry.URL = feed.SiteURL } else { - entryURL, err := url.AbsoluteURL(feed.SiteURL, entry.URL) + entryURL, err := urllib.AbsoluteURL(feed.SiteURL, entry.URL) if err == nil { entry.URL = entryURL } @@ -406,7 +406,7 @@ func (r *rssItem) entryCommentsURL() string { commentsURL := strings.TrimSpace(commentLink.Data) // The comments URL is supposed to be absolute (some feeds publishes incorrect comments URL) // See https://cyber.harvard.edu/rss/rss.html#ltcommentsgtSubelementOfLtitemgt - if url.IsAbsoluteURL(commentsURL) { + if urllib.IsAbsoluteURL(commentsURL) { return commentsURL } } diff --git a/internal/reader/sanitizer/sanitizer.go b/internal/reader/sanitizer/sanitizer.go index 57a5fbff..84c15dc3 100644 --- a/internal/reader/sanitizer/sanitizer.go +++ b/internal/reader/sanitizer/sanitizer.go @@ -12,7 +12,7 @@ import ( "strings" "miniflux.app/v2/internal/config" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "golang.org/x/net/html" ) @@ -141,7 +141,7 @@ func sanitizeAttributes(baseURL, tagName string, attributes []html.Attribute) ([ value = attribute.Val isAnchorLink = true } else { - value, err = url.AbsoluteURL(baseURL, value) + value, err = urllib.AbsoluteURL(baseURL, value) if err != nil { continue } @@ -350,12 +350,12 @@ func isValidIframeSource(baseURL, src string) bool { } // allow iframe from same origin - if url.Domain(baseURL) == url.Domain(src) { + if urllib.Domain(baseURL) == urllib.Domain(src) { return true } // allow iframe from custom invidious instance - if config.Opts != nil && config.Opts.InvidiousInstance() == url.Domain(src) { + if config.Opts != nil && config.Opts.InvidiousInstance() == urllib.Domain(src) { return true } @@ -467,7 +467,7 @@ func sanitizeSrcsetAttr(baseURL, value string) string { imageCandidates := ParseSrcSetAttribute(value) for _, imageCandidate := range imageCandidates { - absoluteURL, err := url.AbsoluteURL(baseURL, imageCandidate.ImageURL) + absoluteURL, err := urllib.AbsoluteURL(baseURL, imageCandidate.ImageURL) if err == nil { imageCandidate.ImageURL = absoluteURL } diff --git a/internal/reader/scraper/scraper.go b/internal/reader/scraper/scraper.go index c6c81c40..b6ddf39d 100644 --- a/internal/reader/scraper/scraper.go +++ b/internal/reader/scraper/scraper.go @@ -13,7 +13,7 @@ import ( "miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/reader/readability" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "github.com/PuerkitoBio/goquery" ) @@ -46,7 +46,7 @@ func Fetch(websiteURL, rules, userAgent string, cookie string, allowSelfSignedCe } // The entry URL could redirect somewhere else. - sameSite := url.Domain(websiteURL) == url.Domain(response.EffectiveURL) + sameSite := urllib.Domain(websiteURL) == urllib.Domain(response.EffectiveURL) websiteURL = response.EffectiveURL if rules == "" { @@ -87,7 +87,7 @@ func scrapContent(page io.Reader, rules string) (string, error) { } func getPredefinedScraperRules(websiteURL string) string { - urlDomain := url.Domain(websiteURL) + urlDomain := urllib.Domain(websiteURL) for domain, rules := range predefinedRules { if strings.Contains(urlDomain, domain) { diff --git a/internal/reader/subscription/finder.go b/internal/reader/subscription/finder.go index 4e07f23c..1683f393 100644 --- a/internal/reader/subscription/finder.go +++ b/internal/reader/subscription/finder.go @@ -14,7 +14,7 @@ import ( "miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/reader/browser" "miniflux.app/v2/internal/reader/parser" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "github.com/PuerkitoBio/goquery" ) @@ -90,7 +90,7 @@ func parseWebPage(websiteURL string, data io.Reader) (Subscriptions, *errors.Loc if feedURL, exists := s.Attr("href"); exists { if feedURL != "" { - subscription.URL, _ = url.AbsoluteURL(websiteURL, feedURL) + subscription.URL, _ = urllib.AbsoluteURL(websiteURL, feedURL) } } @@ -149,20 +149,20 @@ func tryWellKnownUrls(websiteURL, userAgent, cookie, username, password string) "rss/": "rss", } - websiteURLRoot := url.RootURL(websiteURL) + websiteURLRoot := urllib.RootURL(websiteURL) baseURLs := []string{ // Look for knownURLs in the root. websiteURLRoot, } // Look for knownURLs in current subdirectory, such as 'example.com/blog/'. - websiteURL, _ = url.AbsoluteURL(websiteURL, "./") + websiteURL, _ = urllib.AbsoluteURL(websiteURL, "./") if websiteURL != websiteURLRoot { baseURLs = append(baseURLs, websiteURL) } for _, baseURL := range baseURLs { for knownURL, kind := range knownURLs { - fullURL, err := url.AbsoluteURL(baseURL, knownURL) + fullURL, err := urllib.AbsoluteURL(baseURL, knownURL) if err != nil { continue } diff --git a/internal/template/functions.go b/internal/template/functions.go index 08b02411..97ca0f3d 100644 --- a/internal/template/functions.go +++ b/internal/template/functions.go @@ -18,7 +18,7 @@ import ( "miniflux.app/v2/internal/model" "miniflux.app/v2/internal/proxy" "miniflux.app/v2/internal/timezone" - "miniflux.app/v2/internal/url" + "miniflux.app/v2/internal/urllib" "github.com/gorilla/mux" ) @@ -65,7 +65,7 @@ func (f *funcMap) Map() template.FuncMap { "proxyURL": func(link string) string { proxyOption := config.Opts.ProxyOption() - if proxyOption == "all" || (proxyOption != "none" && !url.IsHTTPS(link)) { + if proxyOption == "all" || (proxyOption != "none" && !urllib.IsHTTPS(link)) { return proxy.ProxifyURL(f.router, link) } @@ -80,7 +80,7 @@ func (f *funcMap) Map() template.FuncMap { return false }, "domain": func(websiteURL string) string { - return url.Domain(websiteURL) + return urllib.Domain(websiteURL) }, "hasPrefix": func(str, prefix string) bool { return strings.HasPrefix(str, prefix) diff --git a/internal/url/url.go b/internal/urllib/url.go similarity index 97% rename from internal/url/url.go rename to internal/urllib/url.go index 4f0b0c0f..b3e2a546 100644 --- a/internal/url/url.go +++ b/internal/urllib/url.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -package url // import "miniflux.app/v2/internal/url" +package urllib // import "miniflux.app/v2/internal/urllib" import ( "fmt" diff --git a/internal/url/url_test.go b/internal/urllib/url_test.go similarity index 98% rename from internal/url/url_test.go rename to internal/urllib/url_test.go index 712ad57f..ffd91cf1 100644 --- a/internal/url/url_test.go +++ b/internal/urllib/url_test.go @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. // SPDX-License-Identifier: Apache-2.0 -package url // import "miniflux.app/v2/internal/url" +package urllib // import "miniflux.app/v2/internal/urllib" import "testing"