diff --git a/default.go b/default.go index 78fd53f..63263c8 100644 --- a/default.go +++ b/default.go @@ -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 { diff --git a/default_test.go b/default_test.go index 5e09775..8c72091 100644 --- a/default_test.go +++ b/default_test.go @@ -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) + } +}