fix(template): address regression in string functions for template engine (#142)

It appears that `Sprig` flips the inputs of the `contains`, `hasPrefix`, `replace`
and `hasSuffix` `strings` methods. This appears to be the cause of the regression.

See: https://github.com/Masterminds/sprig/blob/master/functions.go#L149-L152

This results in a regression against the previous implementations of the template
functions.

Signed-off-by: Derek Smith <derek@clokwork.net>
This commit is contained in:
Derek Smith 2021-04-13 16:27:42 -05:00 committed by GitHub
parent 7cc56b1256
commit fdd421b057
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 2 deletions

View file

@ -340,6 +340,13 @@ func (gen *Generator) render(w io.Writer, unreleased *Unreleased, versions []*Ve
pad := strings.Repeat(" ", n)
return pad + strings.ReplaceAll(s, "\n", "\n"+pad)
},
// While Sprig provides these functions, they change the standard input
// order which leads to a regression. For an example see:
// https://github.com/Masterminds/sprig/blob/master/functions.go#L149
"contains": strings.Contains,
"hasPrefix": strings.HasPrefix,
"hasSuffix": strings.HasSuffix,
"replace": strings.Replace,
}
fname := filepath.Base(gen.config.Template)