From a64fd779f82fb8c4512b6a68915dc921f0917c9c Mon Sep 17 00:00:00 2001 From: Kyle Sanderson Date: Mon, 7 Oct 2024 06:55:26 -0700 Subject: [PATCH] fix(wildcard): check name length (#1758) * fix(wildcard): check name length * fix(wildcard): add additional test * fix(wildcard): tests --------- Co-authored-by: ze0s --- pkg/wildcard/match.go | 2 +- pkg/wildcard/match_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/pkg/wildcard/match.go b/pkg/wildcard/match.go index ded4bd7..8e0e2b9 100644 --- a/pkg/wildcard/match.go +++ b/pkg/wildcard/match.go @@ -55,7 +55,7 @@ func match(pattern, name string, simple bool) (matched bool) { } offset := base + i - if name[base:offset] != pattern[base:offset] { + if len(name) < offset || name[base:offset] != pattern[base:offset] { break } diff --git a/pkg/wildcard/match_test.go b/pkg/wildcard/match_test.go index 2134d3b..04e56c7 100644 --- a/pkg/wildcard/match_test.go +++ b/pkg/wildcard/match_test.go @@ -102,6 +102,11 @@ func TestMatch(t *testing.T) { text: "The God of the BrrThe Power of Brr", matched: true, }, + { + pattern: "mysteries?of?the?abandoned*", + text: "them", + matched: false, + }, } // Iterating over the test cases, call the function under test and assert the output. for i, testCase := range testCases {