зеркало из https://github.com/stride3d/SharpYaml.git
Fix lost characters when emitting folded scalars with carriage returns.
This commit is contained in:
Родитель
9a6d64ec45
Коммит
7d1dea8a23
|
@ -1131,10 +1131,10 @@ namespace YamlDotNet.Core
|
||||||
{
|
{
|
||||||
if (!previous_break && !leadingSpaces && character == '\n')
|
if (!previous_break && !leadingSpaces && character == '\n')
|
||||||
{
|
{
|
||||||
do
|
while ((i + 1) < value.Length && IsBreak(value[i + 1]))
|
||||||
{
|
{
|
||||||
++i;
|
++i;
|
||||||
} while (i < value.Length && IsBreak(value[i]));
|
};
|
||||||
|
|
||||||
if (i >= value.Length || value[i] != ' ')
|
if (i >= value.Length || value[i] != ' ')
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,6 +23,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Extensions;
|
||||||
using YamlDotNet.Core;
|
using YamlDotNet.Core;
|
||||||
using YamlDotNet.Core.Events;
|
using YamlDotNet.Core.Events;
|
||||||
|
|
||||||
|
@ -170,5 +171,27 @@ namespace YamlDotNet.UnitTests
|
||||||
{
|
{
|
||||||
ParseAndEmit("test14.yaml");
|
ParseAndEmit("test14.yaml");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Theory]
|
||||||
|
[InlineData("LF hello\nworld")]
|
||||||
|
[InlineData("CRLF hello\r\nworld")]
|
||||||
|
public void FoldedStyleDoesNotLooseCharacters(string text)
|
||||||
|
{
|
||||||
|
var buffer = new StringWriter();
|
||||||
|
var emitter = new Emitter(buffer);
|
||||||
|
emitter.Emit(new StreamStart());
|
||||||
|
emitter.Emit(new DocumentStart(null, null, true));
|
||||||
|
emitter.Emit(new SequenceStart(null, null, false, SequenceStyle.Block));
|
||||||
|
|
||||||
|
emitter.Emit(new Scalar(null, null, text, ScalarStyle.Folded, true, false));
|
||||||
|
|
||||||
|
emitter.Emit(new SequenceEnd());
|
||||||
|
emitter.Emit(new DocumentEnd(true));
|
||||||
|
emitter.Emit(new StreamEnd());
|
||||||
|
|
||||||
|
var yaml = buffer.ToString();
|
||||||
|
Console.WriteLine(yaml);
|
||||||
|
Assert.True(yaml.Contains("world"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Загрузка…
Ссылка в новой задаче