Fix lost characters when emitting folded scalars with carriage returns.

This commit is contained in:
Antoine Aubry 2013-07-03 15:14:38 +01:00
Родитель 9a6d64ec45
Коммит 7d1dea8a23
2 изменённых файлов: 30 добавлений и 7 удалений

Просмотреть файл

@ -1131,10 +1131,10 @@ namespace YamlDotNet.Core
{
if (!previous_break && !leadingSpaces && character == '\n')
{
do
while ((i + 1) < value.Length && IsBreak(value[i + 1]))
{
++i;
} while (i < value.Length && IsBreak(value[i]));
};
if (i >= value.Length || value[i] != ' ')
{

Просмотреть файл

@ -23,6 +23,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using Xunit;
using Xunit.Extensions;
using YamlDotNet.Core;
using YamlDotNet.Core.Events;
@ -170,5 +171,27 @@ namespace YamlDotNet.UnitTests
{
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"));
}
}
}