diff --git a/util/templates/utils.go b/util/templates/utils.go index 4c8887f73..c6558bf4f 100644 --- a/util/templates/utils.go +++ b/util/templates/utils.go @@ -16,6 +16,11 @@ func yamlQuote(value string) string { return value } + // quote multi-line strings with "" and convert line breaks to literal \n + if strings.Contains(value, "\n") { + return `"` + strings.ReplaceAll(value, "\n", "\\n") + `"` + } + input := fmt.Sprintf("key: %s", value) var res struct { diff --git a/util/templates/utils_test.go b/util/templates/utils_test.go index e2459843f..496cda933 100644 --- a/util/templates/utils_test.go +++ b/util/templates/utils_test.go @@ -30,3 +30,9 @@ func TestYamlDecodeLeadingZero(t *testing.T) { p := Param{Type: TypeString} assert.Equal(t, "'0815'", p.yamlQuote("0815")) } + +func TestYamlQuote(t *testing.T) { + assert.Equal(t, `"a\nb\nc"`, yamlQuote(`a +b +c`)) +}