Skip to content

Commit

Permalink
Double-quote multi-line strings in flow style.
Browse files Browse the repository at this point in the history
  • Loading branch information
niemeyer committed Jul 9, 2019
1 parent 0932294 commit 513397e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,11 @@ func (e *encoder) stringv(tag string, in reflect.Value) {
// text that's incompatible with that tag.
switch {
case strings.Contains(s, "\n"):
style = yaml_LITERAL_SCALAR_STYLE
if e.flow {
style = yaml_DOUBLE_QUOTED_SCALAR_STYLE
} else {
style = yaml_LITERAL_SCALAR_STYLE
}
case canUsePlain:
style = yaml_PLAIN_SCALAR_STYLE
default:
Expand Down
5 changes: 5 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,11 @@ var marshalTests = []struct {
} "a,flow"
}{struct{ B, D string }{"c", "e"}},
"a: {b: c, d: e}\n",
}, {
&struct {
A string "a,flow"
}{"b\nc"},
"a: \"b\\nc\"\n",
},

// Unexported field
Expand Down

0 comments on commit 513397e

Please sign in to comment.