Validate host, trim title and description regardless of source
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Tyler 2019-10-16 19:37:11 -04:00
parent 3f71e11018
commit 3cecfb8c8b
1 changed files with 7 additions and 3 deletions

View File

@ -62,8 +62,8 @@ func (api *LinkInfoApi) DefaultLinkHandler(link string) (*LinkInfo, error) {
return nil, errors.New("unsupported scheme")
}
if u.Host == "localhost" {
return nil, errors.New("url is localhost")
if u.Host == "localhost" || u.Host == "" {
return nil, errors.New("invalid host")
} else if ip := net.ParseIP(u.Host); ip != nil && isPrivateIP(ip) {
return nil, errors.New("url is a local ip address")
}
@ -248,15 +248,19 @@ func (api *LinkInfoApi) retrieveHtmlLinkTitle(i *LinkInfo, link string) error {
if attr, exists = metaTags["og:title"]; exists {
i.Title = attr
} else if tag := q.Find("head > title"); tag.Length() > 0 {
i.Title = strings.TrimSpace(tag.Text())
i.Title = tag.Text()
}
i.Title = strings.TrimSpace(i.Title)
if attr, exists = metaTags["og:description"]; exists {
i.Description = attr
} else if attr, exists = metaTags["description"]; exists {
i.Description = attr
}
i.Description = strings.TrimSpace(i.Description)
if attr, exists = metaTags["duration"]; exists {
i.Duration = attr
}