diff --git a/YamlDotNet.Test/Core/EmitterTests.cs b/YamlDotNet.Test/Core/EmitterTests.cs index 277099577..d01d1ec50 100644 --- a/YamlDotNet.Test/Core/EmitterTests.cs +++ b/YamlDotNet.Test/Core/EmitterTests.cs @@ -208,6 +208,19 @@ public void FoldedStyleIsSelectedWhenNewLinesAreFoundInLiteral() yaml.Should().Contain(">"); } + + [Fact] + [Trait("motive", "pr #540")] + public void AllowBlockStyleInMultilineScalarsWithTrailingSpaces() + { + var events = SequenceWith(Scalar("hello \nworld").ImplicitPlain); + + var yaml = EmittedTextFrom(StreamedDocumentWith(events)); + + yaml.Should().Contain("\n"); + } + + [Fact] public void FoldedStyleDoesNotGenerateExtraLineBreaks() { diff --git a/YamlDotNet.Test/Yaml.cs b/YamlDotNet.Test/Yaml.cs index cecae1e1a..f6363a9cd 100644 --- a/YamlDotNet.Test/Yaml.cs +++ b/YamlDotNet.Test/Yaml.cs @@ -103,7 +103,7 @@ public static string Text(string yamlText) } lines = lines - .Select(l => l.Substring(indent.Groups[1].Length)) + .Select(l => l.Length > 0 ? l.Substring(indent.Groups[1].Length) : l) .ToList(); }