MCPcopy Create free account
hub / github.com/daodst/chat / patternMatches

Function patternMatches

internal/pushrules/evaluate.go:147–165  ·  view source on GitHub ↗
(key, pattern string, event *gomatrixserverlib.Event)

Source from the content-addressed store, hash-verified

145}
146
147func patternMatches(key, pattern string, event *gomatrixserverlib.Event) (bool, error) {
148 re, err := globToRegexp(pattern)
149 if err != nil {
150 return false, err
151 }
152
153 var eventMap map[string]interface{}
154 if err = json.Unmarshal(event.JSON(), &eventMap); err != nil {
155 return false, fmt.Errorf("parsing event: %w", err)
156 }
157 v, err := lookupMapPath(strings.Split(key, "."), eventMap)
158 if err != nil {
159 // An unknown path is a benign error that shouldn't stop rule
160 // processing. It's just a non-match.
161 return false, nil
162 }
163
164 return re.MatchString(fmt.Sprint(v)), nil
165}

Callers 3

TestPatternMatchesFunction · 0.85
ruleMatchesFunction · 0.85
conditionMatchesFunction · 0.85

Calls 3

globToRegexpFunction · 0.85
lookupMapPathFunction · 0.85
SplitMethod · 0.80

Tested by 1

TestPatternMatchesFunction · 0.68