ignore template comments, fix bad test data

Signed-off-by: Matt Butcher <matt.butcher@microsoft.com>
pull/8043/head
Matt Butcher 5 years ago
parent b6a3b5fa93
commit 43e48c75c7
No known key found for this signature in database
GPG Key ID: DCD5F5E5EF32C345

@ -188,10 +188,16 @@ func validateNoReleaseTime(manifest []byte) error {
// TODO: I strongly suspect that there are better regexps than these two. // TODO: I strongly suspect that there are better regexps than these two.
var ( var (
badTplStart = regexp.MustCompile(`{{-?[^-\s]+`) badTplStart = regexp.MustCompile(`{{-?[^-\s\/]+`)
badTplEnd = regexp.MustCompile(`[^\s-]+-?}}`) badTplEnd = regexp.MustCompile(`[^\s-\/]+-?}}`)
) )
// validateWhitespaceAroundTemplateDirectives checks for formatting errors on tpl directives
//
// The recommendation is that templates add at least one whitespace character between the
// directive marker ({{ or {{-) and the directive. This enforces that.
//
// See https://github.com/helm/helm/issues/5763
func validateWhitespaceAroundTemplateDirectives(template string) error { func validateWhitespaceAroundTemplateDirectives(template string) error {
badMatches := []string{} badMatches := []string{}
if matches := badTplStart.FindAllString(template, 10); matches != nil { if matches := badTplStart.FindAllString(template, 10); matches != nil {

@ -244,6 +244,7 @@ func TestValidateWhitespaceAroundTemplateDirectives(t *testing.T) {
`{{ legal }}{{illegal }}`: false, `{{ legal }}{{illegal }}`: false,
`{{ legal }}{{- legal -}}`: true, `{{ legal }}{{- legal -}}`: true,
"{{\nlegal\n}}": true, "{{\nlegal\n}}": true,
"{{/* comment */}}": true,
} { } {
if err := validateWhitespaceAroundTemplateDirectives(example); (err == nil) != success { if err := validateWhitespaceAroundTemplateDirectives(example); (err == nil) != success {
st := "failure" st := "failure"

Loading…
Cancel
Save