ignore special character in regex

This commit is contained in:
Carlosokumu 2024-10-09 22:21:11 +03:00
parent c8a5391435
commit 8791753b2a
Signed by untrusted user: carlos
GPG Key ID: 7BD6BC8160A5C953

View File

@ -13,13 +13,9 @@ type Step struct {
} }
func (s *Step) MatchesExpectedContent(content []byte) (bool, error) { func (s *Step) MatchesExpectedContent(content []byte) (bool, error) {
pattern := `.*\?.*|.*` pattern := regexp.QuoteMeta(s.ExpectedContent)
re, err := regexp.Compile(pattern) re, _ := regexp.Compile(pattern)
if err != nil { if re.Match([]byte(content)) {
return false, err
}
// Check if the content matches the regex pattern
if re.Match(content) {
return true, nil return true, nil
} }
return false, nil return false, nil
@ -38,7 +34,8 @@ type TestCase struct {
} }
func (s *TestCase) MatchesExpectedContent(content []byte) (bool, error) { 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 { if err != nil {
return false, err return false, err
} }