YamlDotNet
YamlDotNet copied to clipboard
String starting with tab and comma is incorrectly serialized leading to SemanticErrorException when that yaml is deserialized
The following code is the full code to reproduce the bug. (Its commented.)
var serializer = new SerializerBuilder().Build();
var yaml = serializer.Serialize(new List
Project settings C# <TargetFramework>net6.0-windows10.0.22000.0</TargetFramework> <PackageReference Include="YamlDotNet" Version="12.0.2" />
Thanks
Thank you for the bug report. I'll take a look at it in the next few days. I suspect it's in the node serializer and it's not quoting strings that start with whitespace, it'd be interesting to know if " ,"
also throws an error or is incorrect when deserializing. I suspect it will be missing the leading space.
I bet if we modify this regex to include a whitespace check at the beginning of the string it would fix it.
https://github.com/aaubry/YamlDotNet/blob/02685df84cb2e0b81f327e890968267e4b60e0f0/YamlDotNet/Serialization/EventEmitters/TypeAssigningEventEmitter.cs#L35
After doing that, it would work by calling withquotenecessarystrings on the serializer builder. It'll be a few days before I can test this out and get a fix in though.
This bug also happens to me. After I serialize an object with "\t- a" string, I can't deserialize the yaml. See https://github.com/stakira/OpenUtau/issues/1040
As soon as the next release goes out (in about 10-15 minutes), this will be fixed. You'll need to make sure to include the .WithQuotingNecessaryStrings()
is called on your SerializerBuilder
.
A fix for this issue has been released in version 15.1.2.