Yaml: quote multi-line tempalte parameters (#23344)

This commit is contained in:
andig 2025-08-31 11:32:42 +02:00 • committed by GitHub
parent 643e3ad208
commit 997f84ac18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View file

@ -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 {

View file

@ -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`))
}