From 8791753b2a1e8c9699c16d963d2f0195ecdb8ce2 Mon Sep 17 00:00:00 2001 From: Carlosokumu Date: Wed, 9 Oct 2024 22:21:11 +0300 Subject: [PATCH] ignore special character in regex --- driver/groupdriver.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/driver/groupdriver.go b/driver/groupdriver.go index c6d0a69..9b3796e 100644 --- a/driver/groupdriver.go +++ b/driver/groupdriver.go @@ -13,13 +13,9 @@ type Step struct { } func (s *Step) MatchesExpectedContent(content []byte) (bool, error) { - pattern := `.*\?.*|.*` - re, err := regexp.Compile(pattern) - if err != nil { - return false, err - } - // Check if the content matches the regex pattern - if re.Match(content) { + pattern := regexp.QuoteMeta(s.ExpectedContent) + re, _ := regexp.Compile(pattern) + if re.Match([]byte(content)) { return true, nil } return false, nil @@ -38,7 +34,8 @@ type TestCase struct { } func (s *TestCase) MatchesExpectedContent(content []byte) (bool, error) { - re, err := regexp.Compile(s.ExpectedContent) + pattern := regexp.QuoteMeta(s.ExpectedContent) + re, err := regexp.Compile(pattern) if err != nil { return false, err }