Skip to content

fix(lib): ContainsByteSlice never reports a match - #533

Open
devorun wants to merge 1 commit into
canopy-network:mainfrom
devorun:fix/contains-byte-slice-always-false
Open

fix(lib): ContainsByteSlice never reports a match#533
devorun wants to merge 1 commit into
canopy-network:mainfrom
devorun:fix/contains-byte-slice-always-false

Conversation

@devorun

@devorun devorun commented Aug 20, 2026

Copy link
Copy Markdown

Problem

lib.ContainsByteSlice uses a naked return inside the match branch, so the named return value found is never set to true. The function therefore returns false even when target is present in list:

func ContainsByteSlice(list [][]byte, target []byte) (found bool) {
    for _, item := range list {
        if bytes.Equal(item, target) {
            return // found is still false here
        }
    }
    return
}

This helper fills a real gap because slices.Contains cannot operate on [][]byte ([]byte is not comparable), so any current or future caller relying on it would silently get the wrong answer.

Fix

Return true on a match.

Tests

Added TestContainsByteSlice (table-driven, matching the existing style in util_test.go) covering the target present at the head, middle, and tail, plus the empty-list and absent cases. The presence cases fail against the previous implementation and pass with the fix.

The helper used a naked return inside the match branch, so the named
return value 'found' was never set to true. As a result the function
always returned false even when the target was present in the list.

Return true on a match and add table-driven tests covering presence at
the head, middle, and tail, plus the empty-list and absent cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant