diff --git a/internal/reader/encoding/encoding.go b/internal/reader/encoding/encoding.go index 71f93543..3987a885 100644 --- a/internal/reader/encoding/encoding.go +++ b/internal/reader/encoding/encoding.go @@ -35,8 +35,3 @@ func CharsetReader(charsetLabel string, input io.Reader) (io.Reader, error) { // Transform document to UTF-8 from the specified encoding in XML prolog. return charset.NewReaderLabel(charsetLabel, r) } - -// CharsetReaderFromContentType is used when the encoding is not specified for the input document. -func CharsetReaderFromContentType(contentType string, input io.Reader) (io.Reader, error) { - return charset.NewReader(input, contentType) -} diff --git a/internal/reader/icon/finder.go b/internal/reader/icon/finder.go index 965f14df..835a3a14 100644 --- a/internal/reader/icon/finder.go +++ b/internal/reader/icon/finder.go @@ -15,11 +15,11 @@ import ( "miniflux.app/v2/internal/config" "miniflux.app/v2/internal/crypto" "miniflux.app/v2/internal/model" - "miniflux.app/v2/internal/reader/encoding" "miniflux.app/v2/internal/reader/fetcher" "miniflux.app/v2/internal/urllib" "github.com/PuerkitoBio/goquery" + "golang.org/x/net/html/charset" ) type IconFinder struct { @@ -191,7 +191,7 @@ func findIconURLsFromHTMLDocument(body io.Reader, contentType string) ([]string, "link[rel='apple-touch-icon-precomposed.png']", } - htmlDocumentReader, err := encoding.CharsetReaderFromContentType(contentType, body) + htmlDocumentReader, err := charset.NewReader(body, contentType) if err != nil { return nil, fmt.Errorf("icon: unable to create charset reader: %w", err) } diff --git a/internal/reader/scraper/scraper.go b/internal/reader/scraper/scraper.go index 0a0832d4..a5013c3d 100644 --- a/internal/reader/scraper/scraper.go +++ b/internal/reader/scraper/scraper.go @@ -10,12 +10,12 @@ import ( "strings" "miniflux.app/v2/internal/config" - "miniflux.app/v2/internal/reader/encoding" "miniflux.app/v2/internal/reader/fetcher" "miniflux.app/v2/internal/reader/readability" "miniflux.app/v2/internal/urllib" "github.com/PuerkitoBio/goquery" + "golang.org/x/net/html/charset" ) func ScrapeWebsite(requestBuilder *fetcher.RequestBuilder, websiteURL, rules string) (string, error) { @@ -42,9 +42,9 @@ func ScrapeWebsite(requestBuilder *fetcher.RequestBuilder, websiteURL, rules str var content string var err error - htmlDocumentReader, err := encoding.CharsetReaderFromContentType( - responseHandler.ContentType(), + htmlDocumentReader, err := charset.NewReader( responseHandler.Body(config.Opts.HTTPClientMaxBodySize()), + responseHandler.ContentType(), ) if err != nil { return "", fmt.Errorf("scraper: unable to read HTML document: %v", err) diff --git a/internal/reader/subscription/finder.go b/internal/reader/subscription/finder.go index b3ba290b..a086136a 100644 --- a/internal/reader/subscription/finder.go +++ b/internal/reader/subscription/finder.go @@ -14,12 +14,12 @@ import ( "miniflux.app/v2/internal/integration/rssbridge" "miniflux.app/v2/internal/locale" "miniflux.app/v2/internal/model" - "miniflux.app/v2/internal/reader/encoding" "miniflux.app/v2/internal/reader/fetcher" "miniflux.app/v2/internal/reader/parser" "miniflux.app/v2/internal/urllib" "github.com/PuerkitoBio/goquery" + "golang.org/x/net/html/charset" ) var ( @@ -150,7 +150,7 @@ func (f *SubscriptionFinder) FindSubscriptionsFromWebPage(websiteURL, contentTyp "link[type='application/feed+json']": parser.FormatJSON, } - htmlDocumentReader, err := encoding.CharsetReaderFromContentType(contentType, body) + htmlDocumentReader, err := charset.NewReader(body, contentType) if err != nil { return nil, locale.NewLocalizedErrorWrapper(err, "error.unable_to_parse_html_document", err) }