Skip to content

Commit 762ef91

Browse files
committed
Document matches function behavior for invalid regex patterns
Add comments clarifying that matches() returns false for invalid regex patterns rather than erroring. This is intentional graceful degradation since patterns may be user-provided at runtime. Docs: - Add comment explaining invalid pattern behavior - Add inline comment at error return point
1 parent 1feb5b4 commit 762ef91

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

internal/tmpl/engine.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,14 +1048,15 @@ func isNumericFunc(s string) bool {
10481048
}
10491049

10501050
// matchesFunc checks if string matches regex pattern.
1051+
// Returns false for invalid patterns (graceful degradation, pattern may be user-provided).
10511052
// Security: Go's regexp uses RE2 engine with guaranteed O(n) matching (ReDoS-safe).
10521053
func matchesFunc(pattern, s string) bool {
10531054
// Try to get cached regex
10541055
if cached, ok := regexCache.Load(pattern); ok {
10551056
return cached.(*regexp.Regexp).MatchString(s)
10561057
}
10571058

1058-
// Compile regex
1059+
// Compile regex (returns false for invalid patterns)
10591060
re, err := regexp.Compile(pattern)
10601061
if err != nil {
10611062
return false

0 commit comments

Comments
 (0)