summaryrefslogtreecommitdiff
path: root/internal/reader/icon/finder_test.go
diff options
context:
space:
mode:
authorGravatar Frédéric Guillot <f@miniflux.net> 2023-09-09 14:18:39 -0700
committerGravatar Frédéric Guillot <f@miniflux.net> 2023-09-09 14:59:44 -0700
commit3b94217fb742884f6560ea50f1e750a171e9e380 (patch)
treec34b6e0e4f26feece6fdf17304554276e73936ef /internal/reader/icon/finder_test.go
parent48f6885f4472efbe0e23f990ae8d4545f9a6a73d (diff)
downloadv2-3b94217fb742884f6560ea50f1e750a171e9e380.tar.gz
v2-3b94217fb742884f6560ea50f1e750a171e9e380.tar.zst
v2-3b94217fb742884f6560ea50f1e750a171e9e380.zip
Make sure icon URLs are always absolute
Regression introduced in #1907
Diffstat (limited to 'internal/reader/icon/finder_test.go')
-rw-r--r--internal/reader/icon/finder_test.go51
1 files changed, 49 insertions, 2 deletions
diff --git a/internal/reader/icon/finder_test.go b/internal/reader/icon/finder_test.go
index 93769194..7bc8c3e8 100644
--- a/internal/reader/icon/finder_test.go
+++ b/internal/reader/icon/finder_test.go
@@ -92,12 +92,59 @@ func TestParseDocumentWithWhitespaceIconURL(t *testing.T) {
/static/img/favicon.ico
">`
- iconURL, err := parseDocument("http://www.example.org/", strings.NewReader(html))
+ iconURL, err := findIconURLFromHTMLDocument(strings.NewReader(html))
if err != nil {
t.Fatal(err)
}
- if iconURL != "http://www.example.org/static/img/favicon.ico" {
+ if iconURL != "/static/img/favicon.ico" {
+ t.Errorf(`Invalid icon URL, got %q`, iconURL)
+ }
+}
+
+func TestGenerateIconURL(t *testing.T) {
+ iconURL, err := generateIconURL("https://example.org/", "/favicon.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if iconURL != "https://example.org/favicon.png" {
+ t.Errorf(`Invalid icon URL, got %q`, iconURL)
+ }
+
+ iconURL, err = generateIconURL("https://example.org/", "img/favicon.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if iconURL != "https://example.org/img/favicon.png" {
+ t.Errorf(`Invalid icon URL, got %q`, iconURL)
+ }
+
+ iconURL, err = generateIconURL("https://example.org/", "https://example.org/img/favicon.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if iconURL != "https://example.org/img/favicon.png" {
+ t.Errorf(`Invalid icon URL, got %q`, iconURL)
+ }
+
+ iconURL, err = generateIconURL("https://example.org/", "//example.org/img/favicon.png")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if iconURL != "https://example.org/img/favicon.png" {
+ t.Errorf(`Invalid icon URL, got %q`, iconURL)
+ }
+
+ iconURL, err = generateIconURL("https://example.org/", " ")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ if iconURL != "https://example.org/favicon.ico" {
t.Errorf(`Invalid icon URL, got %q`, iconURL)
}
}