Skip to content

Commit

Permalink
fix(fields): handle nexted fields when excluding (#6359)
Browse files Browse the repository at this point in the history
Signed-off-by: AntoineDao <antoinedao1@gmail.com>
  • Loading branch information
AntoineDao authored Jul 19, 2021
1 parent cfab7db commit bd5a8a9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion util/fields/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (f Cleaner) WillExclude(x string) bool {

func (f Cleaner) matches(x string) bool {
for y := range f.fields {
if strings.HasPrefix(x, y) {
if strings.HasPrefix(x, y) || strings.HasPrefix(y, x) {
return true
}
}
Expand Down
2 changes: 2 additions & 0 deletions util/fields/fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func TestCleaner_WillExclude(t *testing.T) {
assert.False(t, NewCleaner("foo").WillExclude("foo"))
assert.False(t, NewCleaner("foo").WillExclude("foo.bar"))
assert.True(t, NewCleaner("foo").WillExclude("bar"))
assert.False(t, NewCleaner("foo.bar.baz").WillExclude("foo.bar"))

})
t.Run("Exclude", func(t *testing.T) {
assert.True(t, NewCleaner("-foo").WillExclude("foo"))
Expand Down

0 comments on commit bd5a8a9

Please sign in to comment.