diff --git a/YamlDotNet.Benchmark/Program.cs b/YamlDotNet.Benchmark/Program.cs index 9fc2ebd9..00802d17 100644 --- a/YamlDotNet.Benchmark/Program.cs +++ b/YamlDotNet.Benchmark/Program.cs @@ -1,4 +1,11 @@ -using BenchmarkDotNet.Running; -using YamlDotNet.Benchmark; +using YamlDotNet.Serialization; -BenchmarkSwitcher.FromAssembly(typeof(YamlStreamBenchmark).Assembly).Run(args); +var serializer = new SerializerBuilder() + .WithQuotingNecessaryStrings() + .Build(); + +var s = "\t, something"; +var yaml = serializer.Serialize(s); +Console.WriteLine(yaml); +var deserializer = new DeserializerBuilder().Build(); +var value = deserializer.Deserialize(yaml); diff --git a/YamlDotNet.Test/Serialization/SerializationTests.cs b/YamlDotNet.Test/Serialization/SerializationTests.cs index d46bc25e..a67c9ae5 100644 --- a/YamlDotNet.Test/Serialization/SerializationTests.cs +++ b/YamlDotNet.Test/Serialization/SerializationTests.cs @@ -2429,6 +2429,36 @@ public void SerializeEnumAsNumber() Assert.Equal(TestEnumAsNumber.Test1 | TestEnumAsNumber.Test2, v); } + [Fact] + public void TabsGetQuotedWhenQuoteNecessaryStringsIsOn() + { + var serializer = new SerializerBuilder() + .WithQuotingNecessaryStrings() + .Build(); + + var s = "\t, something"; + var yaml = serializer.Serialize(s); + Console.WriteLine(yaml); + var deserializer = new DeserializerBuilder().Build(); + var value = deserializer.Deserialize(yaml); + Assert.Equal(s, value); + } + + [Fact] + public void SpacesGetQuotedWhenQuoteNecessaryStringsIsOn() + { + var serializer = new SerializerBuilder() + .WithQuotingNecessaryStrings() + .Build(); + + var s = " , something"; + var yaml = serializer.Serialize(s); + Console.WriteLine(yaml); + var deserializer = new DeserializerBuilder().Build(); + var value = deserializer.Deserialize(yaml); + Assert.Equal(s, value); + } + [Flags] private enum TestEnumAsNumber { diff --git a/YamlDotNet/Serialization/EventEmitters/TypeAssigningEventEmitter.cs b/YamlDotNet/Serialization/EventEmitters/TypeAssigningEventEmitter.cs index e84b9b69..702907ff 100644 --- a/YamlDotNet/Serialization/EventEmitters/TypeAssigningEventEmitter.cs +++ b/YamlDotNet/Serialization/EventEmitters/TypeAssigningEventEmitter.cs @@ -45,6 +45,7 @@ public sealed class TypeAssigningEventEmitter : ChainedEventEmitter + @"|[-+]?(\.[0-9]+|[0-9]+(\.[0-9]*)?)([eE][-+]?[0-9]+)?" // float number + @"|[-+]?(\.inf|\.Inf|\.INF)" + @"|\.nan|\.NaN|\.NAN" + + @"|\s.*" + @")$"; /// diff --git a/tools/build/AutoNumberToStringConverter.cs b/tools/build/AutoNumberToStringConverter.cs index 1d9cde74..1d406bba 100644 --- a/tools/build/AutoNumberToStringConverter.cs +++ b/tools/build/AutoNumberToStringConverter.cs @@ -29,7 +29,7 @@ public override string Read(ref Utf8JsonReader reader, Type typeToConvert, JsonS if (reader.TokenType == JsonTokenType.String) { - return reader.GetString(); + return reader.GetString()!; } using var document = JsonDocument.ParseValue(ref reader); diff --git a/tools/build/BuildDefinition.cs b/tools/build/BuildDefinition.cs index ee056df0..415a4470 100644 --- a/tools/build/BuildDefinition.cs +++ b/tools/build/BuildDefinition.cs @@ -66,7 +66,7 @@ public static async Task ResolveVersion(Options options, PreviousRel }; jsonOptions.Converters.Add(new AutoNumberToStringConverter()); - version = JsonSerializer.Deserialize(versionJson, jsonOptions); + version = JsonSerializer.Deserialize(versionJson, jsonOptions)!; // Workaround to prevent issues with some consumers of the NuGet API that build // links manually instead of following the links that come in the response. @@ -290,7 +290,7 @@ public static async Task LinkPullRequestsToReleases(GitVersion version) var release = await releaseResponse.EnsureSuccessStatusCode().Content.ReadAsAsync(); - var linkedIssues = Regex.Matches(release.body, @"#(\d+)").Select(m => m.Groups[1].Value); + var linkedIssues = Regex.Matches(release.body ?? string.Empty, @"#(\d+)").Select(m => m.Groups[1].Value); WriteVerbose($"Found the following issues / pull requests: {string.Join(",", linkedIssues)}"); foreach (var issueNumber in linkedIssues) @@ -342,12 +342,12 @@ public static Task Document(Options options) const string ns = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"; - var testDefinitions = report.Root + var testDefinitions = report.Root! .Element(XName.Get("TestDefinitions", ns))! .Elements(XName.Get("UnitTest", ns)) .Select(e => { - var testMethod = e.Element(XName.Get("TestMethod", ns)); + var testMethod = e.Element(XName.Get("TestMethod", ns))!; var sampleClassName = testMethod.Attribute("className")!.Value; var sampleMethodName = testMethod.Attribute("name")!.Value;