From ac9d826b0329ec1f7c3977911de68225e0599a65 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Wed, 18 Oct 2023 01:23:40 +0530 Subject: [PATCH] fix: handle empty content topics in filter subcribe and unsubscribe (#812) * fix: handle empty content topics in filter subcribe and unsubscribe --- waku/v2/protocol/filter/client.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/waku/v2/protocol/filter/client.go b/waku/v2/protocol/filter/client.go index 3b1418361..b9df51edb 100644 --- a/waku/v2/protocol/filter/client.go +++ b/waku/v2/protocol/filter/client.go @@ -24,6 +24,7 @@ import ( "github.com/waku-org/go-waku/waku/v2/protocol/subscription" "github.com/waku-org/go-waku/waku/v2/timesource" "go.uber.org/zap" + "golang.org/x/exp/slices" ) // FilterPushID_v20beta1 is the current Waku Filter protocol identifier used to allow @@ -250,6 +251,9 @@ func (wf *WakuFilterLightNode) Subscribe(ctx context.Context, contentFilter prot if len(contentFilter.ContentTopics) == 0 { return nil, errors.New("at least one content topic is required") } + if slices.Contains[string](contentFilter.ContentTopicsList(), "") { + return nil, errors.New("one or more content topics specified is empty") + } if len(contentFilter.ContentTopics) > MaxContentTopicsPerRequest { return nil, fmt.Errorf("exceeds maximum content topics: %d", MaxContentTopicsPerRequest) @@ -437,6 +441,10 @@ func (wf *WakuFilterLightNode) Unsubscribe(ctx context.Context, contentFilter pr return nil, errors.New("at least one content topic is required") } + if slices.Contains[string](contentFilter.ContentTopicsList(), "") { + return nil, errors.New("one or more content topics specified is empty") + } + if len(contentFilter.ContentTopics) > MaxContentTopicsPerRequest { return nil, fmt.Errorf("exceeds maximum content topics: %d", MaxContentTopicsPerRequest) }