From 997f84ac180974184623f7dc712f18ba9efabdb5 Mon Sep 17 00:00:00 2001 From: andig Date: Sun, 31 Aug 2025 11:32:42 +0200 Subject: [PATCH] Yaml: quote multi-line tempalte parameters (#23344) --- util/templates/utils.go | 5 +++++ util/templates/utils_test.go | 6 ++++++ 2 files changed, 11 insertions(+) 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`)) +}