Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions collections/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ func matchPattern(item, pattern string) bool {
return true
}

if strings.HasPrefix(pattern, "*") && strings.HasSuffix(pattern, "*") {
if strings.Contains(item, strings.TrimPrefix(strings.TrimSuffix(pattern, "*"), "*")) {
Comment thread
yashmehrotra marked this conversation as resolved.
return true
}
}

if strings.HasPrefix(pattern, "*") {
if strings.HasSuffix(item, strings.TrimPrefix(pattern, "*")) {
return true
Expand Down
8 changes: 7 additions & 1 deletion collections/slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ func TestMatchItems(t *testing.T) {
{
name: "Multiple Wildcards",
item: "apple",
patterns: []string{"ap*e", "*p*"},
patterns: []string{"ap*e", "*pl*e"},
expected: false,
},
{
name: "Glob",
item: "apple",
patterns: []string{"*ppl*"},
expected: true,
},
{
name: "Handle whitespaces | should be trimmed",
item: "hello",
Expand Down
Loading