From c2ada7dbaa3bc0fbd500aad6f802d44d99b1cfd8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 27 Jul 2026 03:34:11 +0000 Subject: [PATCH] Prevent nil request panic during resolve --- pkg/download/downloader.go | 3 +++ pkg/download/extension.go | 2 +- pkg/download/extension_test.go | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/pkg/download/downloader.go b/pkg/download/downloader.go index dfba2d6d..289a849c 100644 --- a/pkg/download/downloader.go +++ b/pkg/download/downloader.go @@ -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) { + if req == nil { + return nil, errors.New("invalid request") + } rrId, err := gonanoid.New() if err != nil { return diff --git a/pkg/download/extension.go b/pkg/download/extension.go index c9bb7832..e5912b13 100644 --- a/pkg/download/extension.go +++ b/pkg/download/extension.go @@ -548,7 +548,7 @@ func (s *Script) match(event ActivationEvent, req *base.Request) bool { if s.Event != string(event) { 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 } diff --git a/pkg/download/extension_test.go b/pkg/download/extension_test.go index fd63d9a5..c80592fd 100644 --- a/pkg/download/extension_test.go +++ b/pkg/download/extension_test.go @@ -21,6 +21,24 @@ import ( "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) { setupDownloader(func(downloader *Downloader) { if _, err := downloader.InstallExtensionByFolder("./testdata/extensions/basic", false); err != nil {