You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed that SharpYaml doesn't emit multiline strings in the literal or folded style.
At first, I thought I missed a setting, but after digging a bit in the code this seems unintentional:
First, here's a repro to show what I mean:
using System;using System.Collections.Generic;namespace ConsoleApp;publicstaticclassProgram{publicstaticvoidMain(){vardata=newDictionary<string,string>{{"Key","Foo\r\nBar"}};
Console.WriteLine(new YamlDotNet.Serialization.SerializerBuilder().Build().Serialize(data));
Console.WriteLine("---");
Console.WriteLine(new SharpYaml.Serialization.Serializer(new(){EmitTags=false}).Serialize(data));}}
Output:
Key: >- Foo Bar
---
Key: "Foo\r\nBar"
Bonus points if SharpYaml could use literal style by default instead: 🙂
Key: |- Foo Bar
I suppose you may want to add a setting to tell if the serialized value needs to be round-trippable regarding the \r character, as YAML would normalize the line break to \n on deserialization.
Here's what happens:
The following code turns ScalarStyle.Folded into ScalarStyle.DoubleQuoted when isBlockAllowed is false:
I noticed that SharpYaml doesn't emit multiline strings in the literal or folded style.
At first, I thought I missed a setting, but after digging a bit in the code this seems unintentional:
First, here's a repro to show what I mean:
Output:
Bonus points if SharpYaml could use literal style by default instead: 🙂
I suppose you may want to add a setting to tell if the serialized value needs to be round-trippable regarding the
\r
character, as YAML would normalize the line break to\n
on deserialization.Here's what happens:
The following code turns
ScalarStyle.Folded
intoScalarStyle.DoubleQuoted
whenisBlockAllowed
is false:SharpYaml/src/SharpYaml/Emitter.cs
Lines 1524 to 1530 in 3105d16
Here,
isBlockAllowed
is set to false whenspecial_characters
is true:SharpYaml/src/SharpYaml/Emitter.cs
Lines 549 to 555 in 3105d16
And here,
special_characters
is set to true when!buffer.IsPrintable()
:SharpYaml/src/SharpYaml/Emitter.cs
Lines 462 to 465 in 3105d16
CR and LF are not considered printable:
SharpYaml/src/SharpYaml/Emitter.cs
Lines 1110 to 1117 in 3105d16
I'm not sure at which point a change would need to be applied. YamlDotNet has a different logic for setting
isBlockAllowed
to false.The text was updated successfully, but these errors were encountered: