Yaml: quote multi-line tempalte parameters (#23344)
This commit is contained in:
parent
643e3ad208
commit
997f84ac18
2 changed files with 11 additions and 0 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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`))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue