From 5326a7f8660ea037f7364e9292549582c62a7011 Mon Sep 17 00:00:00 2001 From: Himura Kazuto Date: Mon, 26 Oct 2020 18:23:51 +0300 Subject: [PATCH] Allow block style in multiline scalars with trailing spaces --- YamlDotNet/Core/Emitter.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/YamlDotNet/Core/Emitter.cs b/YamlDotNet/Core/Emitter.cs index 9364f837f..53542f72a 100644 --- a/YamlDotNet/Core/Emitter.cs +++ b/YamlDotNet/Core/Emitter.cs @@ -319,11 +319,13 @@ private void AnalyzeScalar(Scalar scalar) var spaceBreak = false; var previousSpace = false; var previousBreak = false; + var lineOfSpaces = false; var lineBreaks = false; var specialCharacters = !ValueIsRepresentableInOutputEncoding(value); var singleQuotes = false; + var linesOfSpaces = false; var isFirst = true; while (!buffer.EndOfInput) @@ -403,6 +405,7 @@ private void AnalyzeScalar(Scalar scalar) if (previousBreak) { breakSpace = true; + lineOfSpaces = true; } previousSpace = true; @@ -425,6 +428,11 @@ private void AnalyzeScalar(Scalar scalar) spaceBreak = true; } + if (lineOfSpaces) + { + linesOfSpaces = true; + } + previousSpace = false; previousBreak = true; } @@ -432,6 +440,7 @@ private void AnalyzeScalar(Scalar scalar) { previousSpace = false; previousBreak = false; + lineOfSpaces = false; } preceededByWhitespace = buffer.IsWhiteBreakOrZero(); @@ -472,6 +481,9 @@ private void AnalyzeScalar(Scalar scalar) scalarData.isFlowPlainAllowed = false; scalarData.isBlockPlainAllowed = false; scalarData.isSingleQuotedAllowed = false; + } + if (linesOfSpaces) + { scalarData.isBlockAllowed = false; }