From daec175c2895e8d72656949c747d2e7352123bff Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Thu, 26 Jun 2025 21:48:58 +0530 Subject: [PATCH 1/3] feat: add support for *-word-* pattern --- collections/slice.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/collections/slice.go b/collections/slice.go index a5cd3d9..18aa90c 100644 --- a/collections/slice.go +++ b/collections/slice.go @@ -120,6 +120,12 @@ func matchPattern(item, pattern string) bool { return true } + if strings.HasPrefix(pattern, "*") && strings.HasSuffix(pattern, "*") { + if strings.Contains(item, strings.Trim(pattern, "*")) { + return true + } + } + if strings.HasPrefix(pattern, "*") { if strings.HasSuffix(item, strings.TrimPrefix(pattern, "*")) { return true From a7ca6e7244b3f1451de208d340429b1c16a8de9c Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Thu, 26 Jun 2025 22:21:18 +0530 Subject: [PATCH 2/3] chore: update collections/slice.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- collections/slice.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/collections/slice.go b/collections/slice.go index 18aa90c..2d44a76 100644 --- a/collections/slice.go +++ b/collections/slice.go @@ -121,7 +121,7 @@ func matchPattern(item, pattern string) bool { } if strings.HasPrefix(pattern, "*") && strings.HasSuffix(pattern, "*") { - if strings.Contains(item, strings.Trim(pattern, "*")) { + if strings.Contains(item, strings.TrimPrefix(strings.TrimSuffix(pattern, "*"), "*")) { return true } } From b0488d8f85ea6c74a9fb1f7ad3cb8d4848f8c0fd Mon Sep 17 00:00:00 2001 From: Yash Mehrotra Date: Thu, 26 Jun 2025 23:02:33 +0530 Subject: [PATCH 3/3] fix: tests --- collections/slice_test.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/collections/slice_test.go b/collections/slice_test.go index b8a75b6..31bc582 100644 --- a/collections/slice_test.go +++ b/collections/slice_test.go @@ -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",