mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-10 02:20:28 +00:00
Prevent nil request panic during resolve
This commit is contained in:
1 parent
6f0cfdcd91
commit
c2ada7dbaa
3 files changed
+22
-1
No files matched your search
@@ -426,6 +426,9 @@ func ensureResourceRequestRawURLs(parentReq *base.Request, res *base.Resource) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *Downloader) Resolve(req *base.Request, opts *base.Options) (rr *ResolveResult, err error) {
|
func (d *Downloader) Resolve(req *base.Request, opts *base.Options) (rr *ResolveResult, err error) {
|
||||||
|
if req == nil {
|
||||||
|
return nil, errors.New("invalid request")
|
||||||
|
}
|
||||||
rrId, err := gonanoid.New()
|
rrId, err := gonanoid.New()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -548,7 +548,7 @@ func (s *Script) match(event ActivationEvent, req *base.Request) bool {
|
|||||||
if s.Event != string(event) {
|
if s.Event != string(event) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if s.Match == nil || (len(s.Match.Urls) == 0 && len(s.Match.Labels) == 0) {
|
if req == nil || s.Match == nil || (len(s.Match.Urls) == 0 && len(s.Match.Labels) == 0) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,6 +21,24 @@ import (
|
|||||||
"github.com/dop251/goja"
|
"github.com/dop251/goja"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestDownloader_ResolveNilRequest(t *testing.T) {
|
||||||
|
setupDownloader(func(downloader *Downloader) {
|
||||||
|
if _, err := downloader.Resolve(nil, nil); err == nil {
|
||||||
|
t.Fatal("expected invalid request error")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestScript_MatchNilRequest(t *testing.T) {
|
||||||
|
script := &Script{
|
||||||
|
Event: string(EventOnResolve),
|
||||||
|
Match: &Match{Urls: []string{"*://*/*"}},
|
||||||
|
}
|
||||||
|
if script.match(EventOnResolve, nil) {
|
||||||
|
t.Fatal("expected nil request not to match")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestDownloader_InstallExtensionByFolder(t *testing.T) {
|
func TestDownloader_InstallExtensionByFolder(t *testing.T) {
|
||||||
setupDownloader(func(downloader *Downloader) {
|
setupDownloader(func(downloader *Downloader) {
|
||||||
if _, err := downloader.InstallExtensionByFolder("./testdata/extensions/basic", false); err != nil {
|
if _, err := downloader.InstallExtensionByFolder("./testdata/extensions/basic", false); err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user