From e619ea0751e5ceee52059d1fc748fd5e98eb6b68 Mon Sep 17 00:00:00 2001 From: Tyler Date: Thu, 3 Oct 2019 20:02:33 -0400 Subject: [PATCH] Trim space off html parsing for title, add test for retrieveHtmlLinkTitle --- default.go | 2 +- default_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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) + } +}