Skip to content

Commit

Permalink
Append relative base href to siteURL (#99)
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrekHaav committed May 17, 2024
1 parent 122de2a commit 22baa9a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions besticon/besticon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,14 @@ func TestFetchIcons(t *testing.T) {
{"https://www.xing.com/assets/frontend_minified/img/shared/xing_r1.ico", 16, "ico"},
{"https://www.xing.com/favicon.ico", 16, "ico"},
}},

// https://printables.com - <base href="/" - https://github.com/mat/besticon/pull/99
{"https://printables.com", []testFetchIcon{
{"https://www.printables.com/assets/favicons/apple-touch-icon.png", 180, "png"},
{"https://www.printables.com/favicon.ico", 48, "ico"},
{"https://www.printables.com/assets/favicons/favicon-32x32.png", 32, "png"},
{"https://www.printables.com/assets/favicons/favicon-16x16.png", 16, "png"},
}},
}

for _, test := range tests {
Expand Down
3 changes: 3 additions & 0 deletions besticon/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func findIconLinks(siteURL *url.URL, html []byte) ([]string, error) {
func determineBaseURL(siteURL *url.URL, doc *goquery.Document) *url.URL {
baseTagHref := extractBaseTag(doc)
if baseTagHref != "" {
if strings.HasPrefix(baseTagHref, "/") {
return siteURL.JoinPath(baseTagHref)
}
baseTagURL, e := url.Parse(baseTagHref)
if e != nil {
return siteURL
Expand Down
Binary file added besticon/testdata/printables.com.vcr
Binary file not shown.

0 comments on commit 22baa9a

Please sign in to comment.