Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix an error that empty sequence deserialization #134

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VYaml.SourceGenerator/VYamlIncrementalSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Comparer : IEqualityComparer<(GeneratorAttributeSyntaxContext, Compilation

public bool Equals((GeneratorAttributeSyntaxContext, Compilation) x, (GeneratorAttributeSyntaxContext, Compilation) y)
{
return x.Item1.TargetNode.Equals(y.Item1.TargetNode);
return x.Item1.TargetNode.IsEquivalentTo(y.Item1.TargetNode);
}

public int GetHashCode((GeneratorAttributeSyntaxContext, Compilation) obj)
Expand Down
1 change: 1 addition & 0 deletions VYaml.Tests/Parser/YamlParserTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Text;
Expand Down
9 changes: 9 additions & 0 deletions VYaml.Tests/Serialization/SerializerTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using NUnit.Framework;
using VYaml.Internal;
Expand Down Expand Up @@ -150,5 +151,13 @@ public void DeserializeHighDigitNumber()
Assert.That(documents["id2"], Is.InstanceOf<int>());
Assert.That(documents["id3"], Is.InstanceOf<double>());
}

[Test]
public void Deserialize_Empty()
{
var empty = new ReadOnlyMemory<byte>(Array.Empty<byte>());
var result1 = YamlSerializer.Deserialize<dynamic>(empty);
Assert.That(result1, Is.Null);
}
}
}
1 change: 1 addition & 0 deletions VYaml.Unity/Assets/Tests/Parser/YamlParserTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Buffers;
using System.Collections.Generic;
using System.Text;
Expand Down
9 changes: 9 additions & 0 deletions VYaml.Unity/Assets/Tests/Serialization/SerializerTest.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using NUnit.Framework;
using VYaml.Internal;
Expand Down Expand Up @@ -150,5 +151,13 @@ public void DeserializeHighDigitNumber()
Assert.That(documents["id2"], Is.InstanceOf<int>());
Assert.That(documents["id3"], Is.InstanceOf<double>());
}

[Test]
public void Deserialize_Empty()
{
var empty = new ReadOnlyMemory<byte>(Array.Empty<byte>());
var result1 = YamlSerializer.Deserialize<dynamic>(empty);
Assert.That(result1, Is.Null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public static T Deserialize<T>(ref YamlParser parser, YamlSerializerOptions? opt
contextLocal.Reset();

parser.SkipHeader();
if (parser.End) return default!;

var formatter = options.Resolver.GetFormatterWithVerify<T>();
return contextLocal.DeserializeWithAlias(formatter, ref parser);
Expand Down
1 change: 1 addition & 0 deletions VYaml/Serialization/YamlSerializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public static T Deserialize<T>(ref YamlParser parser, YamlSerializerOptions? opt
contextLocal.Reset();

parser.SkipHeader();
if (parser.End) return default!;

var formatter = options.Resolver.GetFormatterWithVerify<T>();
return contextLocal.DeserializeWithAlias(formatter, ref parser);
Expand Down
Loading