-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add log when matches cannot parse the regex and make sure it fails fr…
…om then onward. Update test to confirm invalid regex behaviour.
- Loading branch information
Showing
3 changed files
with
14 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
package condition_action | ||
|
||
import "regexp" | ||
import ( | ||
"fmt" | ||
"regexp" | ||
) | ||
|
||
type MatchesConditionAction struct { | ||
regex *regexp.Regexp | ||
} | ||
|
||
func NewMatchesConditionAction(pattern string) MatchesConditionAction { | ||
regex := regexp.MustCompile(pattern) | ||
func NewMatchesConditionAction(id string, pattern string) MatchesConditionAction { | ||
regex, err := regexp.Compile(pattern) | ||
if err != nil { | ||
fmt.Printf("Failed to initialise [Matches] condition's pattern with ID [%s], pattern [%s] with error [%s]. All condition checks will fail.", id, pattern, err.Error()) | ||
} | ||
|
||
return MatchesConditionAction{ | ||
regex: regex, | ||
} | ||
} | ||
|
||
func (a MatchesConditionAction) CheckCondition(input string, args []string) bool { | ||
if a.regex == nil { | ||
return false | ||
} | ||
return a.regex.Match([]byte(input)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters