Validate host, trim title and description regardless of source
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
3f71e11018
commit
3cecfb8c8b
10
default.go
10
default.go
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user