Add missing check in followTheOnlyLink() that leads to a panic
Bug introduced in PR #1290. Fixes #1631.
This commit is contained in:
parent
bfebf946c2
commit
de1a06e3e8
1 changed files with 10 additions and 0 deletions
|
@ -118,11 +118,17 @@ func followTheOnlyLink(websiteURL, content string, rules, userAgent string, cook
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(document.Find("body").Nodes) == 0 {
|
||||||
|
return content, nil
|
||||||
|
}
|
||||||
|
|
||||||
body := document.Find("body").Nodes[0]
|
body := document.Find("body").Nodes[0]
|
||||||
if body.FirstChild.NextSibling != nil ||
|
if body.FirstChild.NextSibling != nil ||
|
||||||
body.FirstChild.Data != "a" {
|
body.FirstChild.Data != "a" {
|
||||||
return content, nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// the body has only one child of <a>
|
// the body has only one child of <a>
|
||||||
var href string
|
var href string
|
||||||
for _, attr := range body.FirstChild.Attr {
|
for _, attr := range body.FirstChild.Attr {
|
||||||
|
@ -131,16 +137,20 @@ func followTheOnlyLink(websiteURL, content string, rules, userAgent string, cook
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if href == "" {
|
if href == "" {
|
||||||
return content, nil
|
return content, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
href, err = url.AbsoluteURL(websiteURL, href)
|
href, err = url.AbsoluteURL(websiteURL, href)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
sameSite := url.Domain(websiteURL) == url.Domain(href)
|
sameSite := url.Domain(websiteURL) == url.Domain(href)
|
||||||
if sameSite {
|
if sameSite {
|
||||||
return fetchURL(href, rules, userAgent, cookie, allowSelfSignedCertificates, useProxy)
|
return fetchURL(href, rules, userAgent, cookie, allowSelfSignedCertificates, useProxy)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fetchURL(href, rules, userAgent, "", false, false)
|
return fetchURL(href, rules, userAgent, "", false, false)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue