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