Trim space off html parsing for title, add test for retrieveHtmlLinkTitle
This commit is contained in:
parent
75989c9337
commit
e619ea0751
|
@ -156,7 +156,7 @@ func retrieveHtmlLinkTitle(i *LinkInfo, link string) error {
|
|||
if attr, exists = metaTags["og:title"]; exists {
|
||||
i.Title = attr
|
||||
} 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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue