fix: handle empty content topics in filter subcribe and unsubscribe (#812)

* fix: handle empty content topics in filter subcribe and unsubscribe
This commit is contained in:
Prem Chaitanya Prathi 2023-10-18 01:23:40 +05:30 committed by GitHub
parent bfee9964f6
commit ac9d826b03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}