whisper: fixed broken partial topic filtering

This commit is contained in:
Eugene Valeyev 2018-03-23 10:27:55 +03:00
parent 933972d139
commit d7808c8ffb
4 changed files with 8 additions and 16 deletions

View file

@ -220,10 +220,6 @@ func matchSingleTopic(topic TopicType, bt []byte) bool {
bt = bt[:TopicLength] bt = bt[:TopicLength]
} }
if len(bt) < TopicLength {
return false
}
for j, b := range bt { for j, b := range bt {
if topic[j] != b { if topic[j] != b {
return false return false

View file

@ -829,16 +829,16 @@ func TestMatchSingleTopic_WithTail_ReturnTrue(t *testing.T) {
} }
} }
func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) { func TestMatchSingleTopic_PartialTopic_ReturnTrue(t *testing.T) {
bt := []byte("tes") bt := []byte("tes")
topic := BytesToTopic(bt) topic := BytesToTopic([]byte("test"))
if matchSingleTopic(topic, bt) { if !matchSingleTopic(topic, bt) {
t.FailNow() t.FailNow()
} }
} }
func TestMatchSingleTopic_InsufficientLength_ReturnFalse(t *testing.T) { func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) {
bt := []byte("test") bt := []byte("test")
topic := BytesToTopic([]byte("not_equal")) topic := BytesToTopic([]byte("not_equal"))

View file

@ -255,10 +255,6 @@ func matchSingleTopic(topic TopicType, bt []byte) bool {
bt = bt[:TopicLength] bt = bt[:TopicLength]
} }
if len(bt) < TopicLength {
return false
}
for j, b := range bt { for j, b := range bt {
if topic[j] != b { if topic[j] != b {
return false return false

View file

@ -848,16 +848,16 @@ func TestMatchSingleTopic_WithTail_ReturnTrue(t *testing.T) {
} }
} }
func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) { func TestMatchSingleTopic_PartialTopic_ReturnTrue(t *testing.T) {
bt := []byte("tes") bt := []byte("tes")
topic := BytesToTopic(bt) topic := BytesToTopic([]byte("test"))
if matchSingleTopic(topic, bt) { if !matchSingleTopic(topic, bt) {
t.FailNow() t.FailNow()
} }
} }
func TestMatchSingleTopic_InsufficientLength_ReturnFalse(t *testing.T) { func TestMatchSingleTopic_NotEquals_ReturnFalse(t *testing.T) {
bt := []byte("test") bt := []byte("test")
topic := BytesToTopic([]byte("not_equal")) topic := BytesToTopic([]byte("not_equal"))