mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
allow limited recursion in templates
Signed-off-by: zwwhdls <zwwhdls@hotmail.com>
This commit is contained in:
parent
985827d09a
commit
4eda4fa06d
1 changed files with 7 additions and 5 deletions
|
|
@ -83,6 +83,7 @@ type renderable struct {
|
|||
|
||||
const warnStartDelim = "HELM_ERR_START"
|
||||
const warnEndDelim = "HELM_ERR_END"
|
||||
const recursionMaxNums = 1000
|
||||
|
||||
var warnRegex = regexp.MustCompile(warnStartDelim + `(.*)` + warnEndDelim)
|
||||
|
||||
|
|
@ -93,19 +94,20 @@ func warnWrap(warn string) string {
|
|||
// initFunMap creates the Engine's FuncMap and adds context-specific functions.
|
||||
func (e Engine) initFunMap(t *template.Template, referenceTpls map[string]renderable) {
|
||||
funcMap := funcMap()
|
||||
includedNames := make([]string, 0)
|
||||
includedNames := make(map[string]int)
|
||||
|
||||
// Add the 'include' function here so we can close over t.
|
||||
funcMap["include"] = func(name string, data interface{}) (string, error) {
|
||||
var buf strings.Builder
|
||||
for _, n := range includedNames {
|
||||
if n == name {
|
||||
if v, ok := includedNames[name]; ok {
|
||||
if v > recursionMaxNums {
|
||||
return "", errors.Wrapf(fmt.Errorf("unable to execute template"), "rendering template has a nested reference name: %s", name)
|
||||
}
|
||||
includedNames[name] ++
|
||||
} else {
|
||||
includedNames[name] = 1
|
||||
}
|
||||
includedNames = append(includedNames, name)
|
||||
err := t.ExecuteTemplate(&buf, name, data)
|
||||
includedNames = includedNames[:len(includedNames)-1]
|
||||
return buf.String(), err
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue