Validate host, trim title and description regardless of source
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
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")
|
return nil, errors.New("unsupported scheme")
|
||||||
}
|
}
|
||||||
|
|
||||||
if u.Host == "localhost" {
|
if u.Host == "localhost" || u.Host == "" {
|
||||||
return nil, errors.New("url is localhost")
|
return nil, errors.New("invalid host")
|
||||||
} else if ip := net.ParseIP(u.Host); ip != nil && isPrivateIP(ip) {
|
} else if ip := net.ParseIP(u.Host); ip != nil && isPrivateIP(ip) {
|
||||||
return nil, errors.New("url is a local ip address")
|
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 {
|
if attr, exists = metaTags["og:title"]; exists {
|
||||||
i.Title = attr
|
i.Title = attr
|
||||||
} else if tag := q.Find("head > title"); tag.Length() > 0 {
|
} 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 {
|
if attr, exists = metaTags["og:description"]; exists {
|
||||||
i.Description = attr
|
i.Description = attr
|
||||||
} else if attr, exists = metaTags["description"]; exists {
|
} else if attr, exists = metaTags["description"]; exists {
|
||||||
i.Description = attr
|
i.Description = attr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
i.Description = strings.TrimSpace(i.Description)
|
||||||
|
|
||||||
if attr, exists = metaTags["duration"]; exists {
|
if attr, exists = metaTags["duration"]; exists {
|
||||||
i.Duration = attr
|
i.Duration = attr
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue