Parse template when validating it (#49282)

This commit is contained in:
Alexander Weaver
2022-05-19 16:05:34 -05:00
committed by GitHub
parent 0a95d493e3
commit e8b498fe8b
2 changed files with 42 additions and 0 deletions
@@ -2,6 +2,7 @@ package definitions
import (
"fmt"
"html/template"
"regexp"
"strings"
@@ -74,6 +75,11 @@ func (t *MessageTemplate) Validate() error {
return fmt.Errorf("template must have content")
}
_, err := template.New("").Parse(t.Template)
if err != nil {
return fmt.Errorf("invalid template: %w", err)
}
content := strings.TrimSpace(t.Template)
found, err := regexp.MatchString(`\{\{\s*define`, content)
if err != nil {