Rename internal url package to avoid overlap with net/url

This commit is contained in:
Frédéric Guillot 2023-08-13 19:09:01 -07:00
parent 9f465fd70d
commit e5d9f2f5a0
23 changed files with 74 additions and 75 deletions

View file

@ -19,7 +19,7 @@ import (
"miniflux.app/v2/internal/proxy" "miniflux.app/v2/internal/proxy"
"miniflux.app/v2/internal/reader/processor" "miniflux.app/v2/internal/reader/processor"
"miniflux.app/v2/internal/storage" "miniflux.app/v2/internal/storage"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"miniflux.app/v2/internal/validator" "miniflux.app/v2/internal/validator"
) )
@ -39,7 +39,7 @@ func (h *handler) getEntryFromBuilder(w http.ResponseWriter, r *http.Request, b
proxyOption := config.Opts.ProxyOption() proxyOption := config.Opts.ProxyOption()
for i := range entry.Enclosures { 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() { for _, mediaType := range config.Opts.ProxyMediaTypes() {
if strings.HasPrefix(entry.Enclosures[i].MimeType, mediaType+"/") { if strings.HasPrefix(entry.Enclosures[i].MimeType, mediaType+"/") {
entry.Enclosures[i].URL = proxy.AbsoluteProxifyURL(h.router, r.Host, entry.Enclosures[i].URL) entry.Enclosures[i].URL = proxy.AbsoluteProxifyURL(h.router, r.Host, entry.Enclosures[i].URL)

View file

@ -24,7 +24,7 @@ import (
mff "miniflux.app/v2/internal/reader/handler" mff "miniflux.app/v2/internal/reader/handler"
mfs "miniflux.app/v2/internal/reader/subscription" mfs "miniflux.app/v2/internal/reader/subscription"
"miniflux.app/v2/internal/storage" "miniflux.app/v2/internal/storage"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"miniflux.app/v2/internal/validator" "miniflux.app/v2/internal/validator"
) )
@ -843,7 +843,7 @@ func (h *handler) streamItemContents(w http.ResponseWriter, r *http.Request) {
proxyOption := config.Opts.ProxyOption() proxyOption := config.Opts.ProxyOption()
for i := range entry.Enclosures { 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() { for _, mediaType := range config.Opts.ProxyMediaTypes() {
if strings.HasPrefix(entry.Enclosures[i].MimeType, mediaType+"/") { if strings.HasPrefix(entry.Enclosures[i].MimeType, mediaType+"/") {
entry.Enclosures[i].URL = proxy.AbsoluteProxifyURL(h.router, r.Host, entry.Enclosures[i].URL) entry.Enclosures[i].URL = proxy.AbsoluteProxifyURL(h.router, r.Host, entry.Enclosures[i].URL)

View file

@ -11,7 +11,7 @@ import (
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
"miniflux.app/v2/internal/model" "miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
const defaultClientTimeout = 1 * time.Second const defaultClientTimeout = 1 * time.Second
@ -34,7 +34,7 @@ func (c *Client) PushEntry(entry *model.Entry) error {
} }
_, err := net.DialTimeout("tcp", c.baseURL, defaultClientTimeout) _, err := net.DialTimeout("tcp", c.baseURL, defaultClientTimeout)
if err != nil { if err != nil {
apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/notify") apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/notify")
if err != nil { if err != nil {
return fmt.Errorf(`apprise: invalid API endpoint: %v`, err) return fmt.Errorf(`apprise: invalid API endpoint: %v`, err)
} }

View file

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
// Document structure of an Espial document // Document structure of an Espial document
@ -42,7 +42,7 @@ func (c *Client) AddEntry(link, title, content, tags string) error {
Tags: tags, Tags: tags,
} }
apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/api/add") apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/add")
if err != nil { if err != nil {
return fmt.Errorf(`espial: invalid API endpoint: %v`, err) return fmt.Errorf(`espial: invalid API endpoint: %v`, err)
} }

View file

@ -8,7 +8,7 @@ import (
"strings" "strings"
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
// Document structure of a Linkding document // Document structure of a Linkding document
@ -49,7 +49,7 @@ func (c *Client) AddEntry(title, entryURL string) error {
Unread: c.unread, Unread: c.unread,
} }
apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/api/bookmarks/") apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/api/bookmarks/")
if err != nil { if err != nil {
return fmt.Errorf(`linkding: invalid API endpoint: %v`, err) return fmt.Errorf(`linkding: invalid API endpoint: %v`, err)
} }

View file

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
// Document structure of a Nununx Keeper document // Document structure of a Nununx Keeper document
@ -42,7 +42,7 @@ func (c *Client) AddEntry(link, title, content string) error {
ContentType: "text/html", ContentType: "text/html",
} }
apiEndpoint, err := url.JoinBaseURLAndPath(c.baseURL, "/v2/documents") apiEndpoint, err := urllib.JoinBaseURLAndPath(c.baseURL, "/v2/documents")
if err != nil { if err != nil {
return fmt.Errorf(`nunux-keeper: invalid API endpoint: %v`, err) return fmt.Errorf(`nunux-keeper: invalid API endpoint: %v`, err)
} }

View file

@ -14,7 +14,7 @@ import (
"strings" "strings"
"time" "time"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"miniflux.app/v2/internal/version" "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") 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 { if err != nil {
return fmt.Errorf("shaarli: invalid API endpoint: %v", err) return fmt.Errorf("shaarli: invalid API endpoint: %v", err)
} }

View file

@ -10,7 +10,7 @@ import (
"net/http" "net/http"
"time" "time"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"miniflux.app/v2/internal/version" "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) 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 { if err != nil {
return fmt.Errorf("shiori: invalid API endpoint: %v", err) 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) { 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 { if err != nil {
return "", fmt.Errorf("shiori: invalid API endpoint: %v", err) return "", fmt.Errorf("shiori: invalid API endpoint: %v", err)
} }

View file

@ -10,7 +10,7 @@ import (
"net/url" "net/url"
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
internal_url "miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
// Client represents a Wallabag client. // 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 { 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 { if err != nil {
return fmt.Errorf("wallbag: unable to generate entries endpoint: %v", err) 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("username", c.username)
values.Add("password", c.password) 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 { if err != nil {
return "", fmt.Errorf("wallbag: unable to generate token endpoint: %v", err) return "", fmt.Errorf("wallbag: unable to generate token endpoint: %v", err)
} }

View file

@ -8,7 +8,7 @@ import (
"miniflux.app/v2/internal/config" "miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/reader/sanitizer" "miniflux.app/v2/internal/reader/sanitizer"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
"github.com/gorilla/mux" "github.com/gorilla/mux"
@ -45,7 +45,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter,
case "image": case "image":
doc.Find("img").Each(func(i int, img *goquery.Selection) { doc.Find("img").Each(func(i int, img *goquery.Selection) {
if srcAttrValue, ok := img.Attr("src"); ok { 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)) img.SetAttr("src", proxifyFunction(router, srcAttrValue))
} }
} }
@ -64,7 +64,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter,
case "audio": case "audio":
doc.Find("audio").Each(func(i int, audio *goquery.Selection) { doc.Find("audio").Each(func(i int, audio *goquery.Selection) {
if srcAttrValue, ok := audio.Attr("src"); ok { 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)) 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) { doc.Find("audio source").Each(func(i int, sourceElement *goquery.Selection) {
if srcAttrValue, ok := sourceElement.Attr("src"); ok { 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)) sourceElement.SetAttr("src", proxifyFunction(router, srcAttrValue))
} }
} }
@ -81,7 +81,7 @@ func genericProxyRewriter(router *mux.Router, proxifyFunction urlProxyRewriter,
case "video": case "video":
doc.Find("video").Each(func(i int, video *goquery.Selection) { doc.Find("video").Each(func(i int, video *goquery.Selection) {
if srcAttrValue, ok := video.Attr("src"); ok { 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)) 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) { doc.Find("video source").Each(func(i int, sourceElement *goquery.Selection) {
if srcAttrValue, ok := sourceElement.Attr("src"); ok { 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)) sourceElement.SetAttr("src", proxifyFunction(router, srcAttrValue))
} }
} }
@ -109,7 +109,7 @@ func proxifySourceSet(element *goquery.Selection, router *mux.Router, proxifyFun
imageCandidates := sanitizer.ParseSrcSetAttribute(srcsetAttrValue) imageCandidates := sanitizer.ParseSrcSetAttribute(srcsetAttrValue)
for _, imageCandidate := range imageCandidates { 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) imageCandidate.ImageURL = proxifyFunction(router, imageCandidate.ImageURL)
} }
} }

View file

@ -14,7 +14,7 @@ import (
"miniflux.app/v2/internal/model" "miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/date"
"miniflux.app/v2/internal/reader/sanitizer" "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 // 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) feed := new(model.Feed)
feedURL := a.Links.firstLinkWithRelation("self") feedURL := a.Links.firstLinkWithRelation("self")
feed.FeedURL, err = url.AbsoluteURL(baseURL, feedURL) feed.FeedURL, err = urllib.AbsoluteURL(baseURL, feedURL)
if err != nil { if err != nil {
feed.FeedURL = feedURL feed.FeedURL = feedURL
} }
siteURL := a.Links.originalLink() siteURL := a.Links.originalLink()
feed.SiteURL, err = url.AbsoluteURL(baseURL, siteURL) feed.SiteURL, err = urllib.AbsoluteURL(baseURL, siteURL)
if err != nil { if err != nil {
feed.SiteURL = siteURL feed.SiteURL = siteURL
} }
@ -50,7 +50,7 @@ func (a *atom03Feed) Transform(baseURL string) *model.Feed {
for _, entry := range a.Entries { for _, entry := range a.Entries {
item := entry.Transform() item := entry.Transform()
entryURL, err := url.AbsoluteURL(feed.SiteURL, item.URL) entryURL, err := urllib.AbsoluteURL(feed.SiteURL, item.URL)
if err == nil { if err == nil {
item.URL = entryURL item.URL = entryURL
} }

View file

@ -16,7 +16,7 @@ import (
"miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/date"
"miniflux.app/v2/internal/reader/media" "miniflux.app/v2/internal/reader/media"
"miniflux.app/v2/internal/reader/sanitizer" "miniflux.app/v2/internal/reader/sanitizer"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
// Specs: // Specs:
@ -38,13 +38,13 @@ func (a *atom10Feed) Transform(baseURL string) *model.Feed {
feed := new(model.Feed) feed := new(model.Feed)
feedURL := a.Links.firstLinkWithRelation("self") feedURL := a.Links.firstLinkWithRelation("self")
feed.FeedURL, err = url.AbsoluteURL(baseURL, feedURL) feed.FeedURL, err = urllib.AbsoluteURL(baseURL, feedURL)
if err != nil { if err != nil {
feed.FeedURL = feedURL feed.FeedURL = feedURL
} }
siteURL := a.Links.originalLink() siteURL := a.Links.originalLink()
feed.SiteURL, err = url.AbsoluteURL(baseURL, siteURL) feed.SiteURL, err = urllib.AbsoluteURL(baseURL, siteURL)
if err != nil { if err != nil {
feed.SiteURL = siteURL feed.SiteURL = siteURL
} }
@ -58,7 +58,7 @@ func (a *atom10Feed) Transform(baseURL string) *model.Feed {
for _, entry := range a.Entries { for _, entry := range a.Entries {
item := entry.Transform() item := entry.Transform()
entryURL, err := url.AbsoluteURL(feed.SiteURL, item.URL) entryURL, err := urllib.AbsoluteURL(feed.SiteURL, item.URL)
if err == nil { if err == nil {
item.URL = entryURL 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. // 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 { func (a *atom10Entry) entryCommentsURL() string {
commentsURL := a.Links.firstLinkWithRelationAndType("replies", "text/html", "application/xhtml+xml") commentsURL := a.Links.firstLinkWithRelationAndType("replies", "text/html", "application/xhtml+xml")
if url.IsAbsoluteURL(commentsURL) { if urllib.IsAbsoluteURL(commentsURL) {
return commentsURL return commentsURL
} }
return "" return ""

View file

@ -7,16 +7,15 @@ import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"io" "io"
"net/url"
"strings" "strings"
stdlib_url "net/url"
"miniflux.app/v2/internal/config" "miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/crypto" "miniflux.app/v2/internal/crypto"
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
"miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/logger"
"miniflux.app/v2/internal/model" "miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
) )
@ -24,7 +23,7 @@ import (
// FindIcon try to find the website's icon. // FindIcon try to find the website's icon.
func FindIcon(websiteURL, iconURL, userAgent string, fetchViaProxy, allowSelfSignedCertificates bool) (*model.Icon, error) { func FindIcon(websiteURL, iconURL, userAgent string, fetchViaProxy, allowSelfSignedCertificates bool) (*model.Icon, error) {
if iconURL == "" { 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) logger.Debug("[FindIcon] Trying to find an icon: rootURL=%q websiteURL=%q userAgent=%q", rootURL, websiteURL, userAgent)
clt := client.NewClientWithConfig(rootURL, config.Opts) clt := client.NewClientWithConfig(rootURL, config.Opts)
@ -90,9 +89,9 @@ func parseDocument(websiteURL string, data io.Reader) (string, error) {
} }
if iconURL == "" { if iconURL == "" {
iconURL = url.RootURL(websiteURL) + "favicon.ico" iconURL = urllib.RootURL(websiteURL) + "favicon.ico"
} else { } else {
iconURL, _ = url.AbsoluteURL(websiteURL, iconURL) iconURL, _ = urllib.AbsoluteURL(websiteURL, iconURL)
} }
return iconURL, nil 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) return nil, fmt.Errorf(`icon: invalid data %q (%v)`, value, err)
} }
case "": case "":
decodedData, err := stdlib_url.QueryUnescape(data) decodedData, err := url.QueryUnescape(data)
if err != nil { if err != nil {
return nil, fmt.Errorf(`icon: unable to decode data URL %q`, value) return nil, fmt.Errorf(`icon: unable to decode data URL %q`, value)
} }

View file

@ -12,7 +12,7 @@ import (
"miniflux.app/v2/internal/model" "miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/date"
"miniflux.app/v2/internal/reader/sanitizer" "miniflux.app/v2/internal/reader/sanitizer"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
type jsonFeed struct { type jsonFeed struct {
@ -67,12 +67,12 @@ func (j *jsonFeed) Transform(baseURL string) *model.Feed {
feed := new(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 { if err != nil {
feed.FeedURL = j.FeedURL feed.FeedURL = j.FeedURL
} }
feed.SiteURL, err = url.AbsoluteURL(baseURL, j.SiteURL) feed.SiteURL, err = urllib.AbsoluteURL(baseURL, j.SiteURL)
if err != nil { if err != nil {
feed.SiteURL = j.SiteURL feed.SiteURL = j.SiteURL
} }
@ -90,7 +90,7 @@ func (j *jsonFeed) Transform(baseURL string) *model.Feed {
for _, item := range j.Items { for _, item := range j.Items {
entry := item.Transform() entry := item.Transform()
entryURL, err := url.AbsoluteURL(feed.SiteURL, entry.URL) entryURL, err := urllib.AbsoluteURL(feed.SiteURL, entry.URL)
if err == nil { if err == nil {
entry.URL = entryURL entry.URL = entryURL
} }

View file

@ -14,7 +14,7 @@ import (
"miniflux.app/v2/internal/model" "miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/date"
"miniflux.app/v2/internal/reader/sanitizer" "miniflux.app/v2/internal/reader/sanitizer"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
type rdfFeed struct { type rdfFeed struct {
@ -30,7 +30,7 @@ func (r *rdfFeed) Transform(baseURL string) *model.Feed {
feed := new(model.Feed) feed := new(model.Feed)
feed.Title = sanitizer.StripTags(r.Title) feed.Title = sanitizer.StripTags(r.Title)
feed.FeedURL = baseURL feed.FeedURL = baseURL
feed.SiteURL, err = url.AbsoluteURL(baseURL, r.Link) feed.SiteURL, err = urllib.AbsoluteURL(baseURL, r.Link)
if err != nil { if err != nil {
feed.SiteURL = r.Link feed.SiteURL = r.Link
} }
@ -44,7 +44,7 @@ func (r *rdfFeed) Transform(baseURL string) *model.Feed {
if entry.URL == "" { if entry.URL == "" {
entry.URL = feed.SiteURL entry.URL = feed.SiteURL
} else { } else {
entryURL, err := url.AbsoluteURL(feed.SiteURL, entry.URL) entryURL, err := urllib.AbsoluteURL(feed.SiteURL, entry.URL)
if err == nil { if err == nil {
entry.URL = entryURL entry.URL = entryURL
} }

View file

@ -10,7 +10,7 @@ import (
"miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/logger"
"miniflux.app/v2/internal/model" "miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
type rule struct { type rule struct {
@ -116,7 +116,7 @@ func applyRule(entryURL string, entry *model.Entry, rule rule) {
} }
func getPredefinedRewriteRules(entryURL string) string { func getPredefinedRewriteRules(entryURL string) string {
urlDomain := url.Domain(entryURL) urlDomain := urllib.Domain(entryURL)
for domain, rules := range predefinedRules { for domain, rules := range predefinedRules {
if strings.Contains(urlDomain, domain) { if strings.Contains(urlDomain, domain) {
return rules return rules

View file

@ -17,7 +17,7 @@ import (
"miniflux.app/v2/internal/reader/date" "miniflux.app/v2/internal/reader/date"
"miniflux.app/v2/internal/reader/media" "miniflux.app/v2/internal/reader/media"
"miniflux.app/v2/internal/reader/sanitizer" "miniflux.app/v2/internal/reader/sanitizer"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
) )
// Specs: https://cyber.harvard.edu/rss/rss.html // Specs: https://cyber.harvard.edu/rss/rss.html
@ -42,13 +42,13 @@ func (r *rssFeed) Transform(baseURL string) *model.Feed {
feed := new(model.Feed) feed := new(model.Feed)
siteURL := r.siteURL() siteURL := r.siteURL()
feed.SiteURL, err = url.AbsoluteURL(baseURL, siteURL) feed.SiteURL, err = urllib.AbsoluteURL(baseURL, siteURL)
if err != nil { if err != nil {
feed.SiteURL = siteURL feed.SiteURL = siteURL
} }
feedURL := r.feedURL() feedURL := r.feedURL()
feed.FeedURL, err = url.AbsoluteURL(baseURL, feedURL) feed.FeedURL, err = urllib.AbsoluteURL(baseURL, feedURL)
if err != nil { if err != nil {
feed.FeedURL = feedURL feed.FeedURL = feedURL
} }
@ -69,7 +69,7 @@ func (r *rssFeed) Transform(baseURL string) *model.Feed {
if entry.URL == "" { if entry.URL == "" {
entry.URL = feed.SiteURL entry.URL = feed.SiteURL
} else { } else {
entryURL, err := url.AbsoluteURL(feed.SiteURL, entry.URL) entryURL, err := urllib.AbsoluteURL(feed.SiteURL, entry.URL)
if err == nil { if err == nil {
entry.URL = entryURL entry.URL = entryURL
} }
@ -406,7 +406,7 @@ func (r *rssItem) entryCommentsURL() string {
commentsURL := strings.TrimSpace(commentLink.Data) commentsURL := strings.TrimSpace(commentLink.Data)
// The comments URL is supposed to be absolute (some feeds publishes incorrect comments URL) // The comments URL is supposed to be absolute (some feeds publishes incorrect comments URL)
// See https://cyber.harvard.edu/rss/rss.html#ltcommentsgtSubelementOfLtitemgt // See https://cyber.harvard.edu/rss/rss.html#ltcommentsgtSubelementOfLtitemgt
if url.IsAbsoluteURL(commentsURL) { if urllib.IsAbsoluteURL(commentsURL) {
return commentsURL return commentsURL
} }
} }

View file

@ -12,7 +12,7 @@ import (
"strings" "strings"
"miniflux.app/v2/internal/config" "miniflux.app/v2/internal/config"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"golang.org/x/net/html" "golang.org/x/net/html"
) )
@ -141,7 +141,7 @@ func sanitizeAttributes(baseURL, tagName string, attributes []html.Attribute) ([
value = attribute.Val value = attribute.Val
isAnchorLink = true isAnchorLink = true
} else { } else {
value, err = url.AbsoluteURL(baseURL, value) value, err = urllib.AbsoluteURL(baseURL, value)
if err != nil { if err != nil {
continue continue
} }
@ -350,12 +350,12 @@ func isValidIframeSource(baseURL, src string) bool {
} }
// allow iframe from same origin // allow iframe from same origin
if url.Domain(baseURL) == url.Domain(src) { if urllib.Domain(baseURL) == urllib.Domain(src) {
return true return true
} }
// allow iframe from custom invidious instance // 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 return true
} }
@ -467,7 +467,7 @@ func sanitizeSrcsetAttr(baseURL, value string) string {
imageCandidates := ParseSrcSetAttribute(value) imageCandidates := ParseSrcSetAttribute(value)
for _, imageCandidate := range imageCandidates { for _, imageCandidate := range imageCandidates {
absoluteURL, err := url.AbsoluteURL(baseURL, imageCandidate.ImageURL) absoluteURL, err := urllib.AbsoluteURL(baseURL, imageCandidate.ImageURL)
if err == nil { if err == nil {
imageCandidate.ImageURL = absoluteURL imageCandidate.ImageURL = absoluteURL
} }

View file

@ -13,7 +13,7 @@ import (
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
"miniflux.app/v2/internal/logger" "miniflux.app/v2/internal/logger"
"miniflux.app/v2/internal/reader/readability" "miniflux.app/v2/internal/reader/readability"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"github.com/PuerkitoBio/goquery" "github.com/PuerkitoBio/goquery"
) )
@ -46,7 +46,7 @@ func Fetch(websiteURL, rules, userAgent string, cookie string, allowSelfSignedCe
} }
// The entry URL could redirect somewhere else. // 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 websiteURL = response.EffectiveURL
if rules == "" { if rules == "" {
@ -87,7 +87,7 @@ func scrapContent(page io.Reader, rules string) (string, error) {
} }
func getPredefinedScraperRules(websiteURL string) string { func getPredefinedScraperRules(websiteURL string) string {
urlDomain := url.Domain(websiteURL) urlDomain := urllib.Domain(websiteURL)
for domain, rules := range predefinedRules { for domain, rules := range predefinedRules {
if strings.Contains(urlDomain, domain) { if strings.Contains(urlDomain, domain) {

View file

@ -14,7 +14,7 @@ import (
"miniflux.app/v2/internal/http/client" "miniflux.app/v2/internal/http/client"
"miniflux.app/v2/internal/reader/browser" "miniflux.app/v2/internal/reader/browser"
"miniflux.app/v2/internal/reader/parser" "miniflux.app/v2/internal/reader/parser"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"github.com/PuerkitoBio/goquery" "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, exists := s.Attr("href"); exists {
if feedURL != "" { 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", "rss/": "rss",
} }
websiteURLRoot := url.RootURL(websiteURL) websiteURLRoot := urllib.RootURL(websiteURL)
baseURLs := []string{ baseURLs := []string{
// Look for knownURLs in the root. // Look for knownURLs in the root.
websiteURLRoot, websiteURLRoot,
} }
// Look for knownURLs in current subdirectory, such as 'example.com/blog/'. // Look for knownURLs in current subdirectory, such as 'example.com/blog/'.
websiteURL, _ = url.AbsoluteURL(websiteURL, "./") websiteURL, _ = urllib.AbsoluteURL(websiteURL, "./")
if websiteURL != websiteURLRoot { if websiteURL != websiteURLRoot {
baseURLs = append(baseURLs, websiteURL) baseURLs = append(baseURLs, websiteURL)
} }
for _, baseURL := range baseURLs { for _, baseURL := range baseURLs {
for knownURL, kind := range knownURLs { for knownURL, kind := range knownURLs {
fullURL, err := url.AbsoluteURL(baseURL, knownURL) fullURL, err := urllib.AbsoluteURL(baseURL, knownURL)
if err != nil { if err != nil {
continue continue
} }

View file

@ -18,7 +18,7 @@ import (
"miniflux.app/v2/internal/model" "miniflux.app/v2/internal/model"
"miniflux.app/v2/internal/proxy" "miniflux.app/v2/internal/proxy"
"miniflux.app/v2/internal/timezone" "miniflux.app/v2/internal/timezone"
"miniflux.app/v2/internal/url" "miniflux.app/v2/internal/urllib"
"github.com/gorilla/mux" "github.com/gorilla/mux"
) )
@ -65,7 +65,7 @@ func (f *funcMap) Map() template.FuncMap {
"proxyURL": func(link string) string { "proxyURL": func(link string) string {
proxyOption := config.Opts.ProxyOption() 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) return proxy.ProxifyURL(f.router, link)
} }
@ -80,7 +80,7 @@ func (f *funcMap) Map() template.FuncMap {
return false return false
}, },
"domain": func(websiteURL string) string { "domain": func(websiteURL string) string {
return url.Domain(websiteURL) return urllib.Domain(websiteURL)
}, },
"hasPrefix": func(str, prefix string) bool { "hasPrefix": func(str, prefix string) bool {
return strings.HasPrefix(str, prefix) return strings.HasPrefix(str, prefix)

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package url // import "miniflux.app/v2/internal/url" package urllib // import "miniflux.app/v2/internal/urllib"
import ( import (
"fmt" "fmt"

View file

@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved. // SPDX-FileCopyrightText: Copyright The Miniflux Authors. All rights reserved.
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
package url // import "miniflux.app/v2/internal/url" package urllib // import "miniflux.app/v2/internal/urllib"
import "testing" import "testing"