Trim space off html parsing for title, add test for retrieveHtmlLinkTitle

This commit is contained in:
Tyler 2019-10-03 20:02:33 -04:00
parent 75989c9337
commit e619ea0751
2 changed files with 13 additions and 1 deletions

View File

@ -156,7 +156,7 @@ func retrieveHtmlLinkTitle(i *LinkInfo, link string) error {
if attr, exists = metaTags["og:title"]; exists { if attr, exists = metaTags["og:title"]; exists {
i.Title = attr i.Title = attr
} else if tag := q.Find("title"); tag.Length() > 0 { } else if tag := q.Find("title"); tag.Length() > 0 {
i.Title = tag.Text() i.Title = strings.TrimSpace(tag.Text())
} }
if attr, exists = metaTags["og:description"]; exists { if attr, exists = metaTags["og:description"]; exists {

View File

@ -49,3 +49,15 @@ func Test_defaultLinkHandler(t *testing.T) {
} }
} }
} }
func Test_retrieveHtmlLinkTitle(t *testing.T) {
ret := &LinkInfo{}
if err := retrieveHtmlLinkTitle(ret, "http://example.com"); err != nil {
t.Fatal("Unable to retrieve html link title:", err)
}
if ret.Title != "Example Domain" {
t.Fatal("Unexpected title", ret.Title)
}
}