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 {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if len(document.Find("body").Nodes) == 0 {
|
||||
return content, nil
|
||||
}
|
||||
|
||||
body := document.Find("body").Nodes[0]
|
||||
if body.FirstChild.NextSibling != nil ||
|
||||
body.FirstChild.Data != "a" {
|
||||
return content, nil
|
||||
}
|
||||
|
||||
// the body has only one child of <a>
|
||||
var href string
|
||||
for _, attr := range body.FirstChild.Attr {
|
||||
|
@ -131,16 +137,20 @@ func followTheOnlyLink(websiteURL, content string, rules, userAgent string, cook
|
|||
break
|
||||
}
|
||||
}
|
||||
|
||||
if href == "" {
|
||||
return content, nil
|
||||
}
|
||||
|
||||
href, err = url.AbsoluteURL(websiteURL, href)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
sameSite := url.Domain(websiteURL) == url.Domain(href)
|
||||
if sameSite {
|
||||
return fetchURL(href, rules, userAgent, cookie, allowSelfSignedCertificates, useProxy)
|
||||
}
|
||||
|
||||
return fetchURL(href, rules, userAgent, "", false, false)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue