diff --git a/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs b/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs index d1475c5fe..913f5aa89 100644 --- a/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs +++ b/YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs @@ -47,22 +47,26 @@ public void LoadSimpleDocument() Assert.Equal(YamlNodeType.Scalar, stream.Documents[0].RootNode.NodeType); } - [Fact] - public void AccessingAllNodesOnInfinitelyRecursiveDocumentThrows() + [Theory] + [InlineData("&a [*a]")] + [InlineData("?\n key: &id1\n recursion: *id1\n: foo")] + public void AccessingAllNodesOnInfinitelyRecursiveDocumentThrows(string yaml) { var stream = new YamlStream(); - stream.Load(Yaml.ParserForText("&a [*a]")); + stream.Load(Yaml.ParserForText(yaml)); var accessAllNodes = new Action(() => stream.Documents.Single().AllNodes.ToList()); accessAllNodes.ShouldThrow("because the document is infinitely recursive."); } - [Fact] - public void InfinitelyRecursiveNodeToStringSucceeds() + [Theory] + [InlineData("&a [*a]")] + [InlineData("?\n key: &id1\n recursion: *id1\n: foo")] + public void InfinitelyRecursiveNodeToStringSucceeds(string yaml) { var stream = new YamlStream(); - stream.Load(Yaml.ParserForText("&a [*a]")); + stream.Load(Yaml.ParserForText(yaml)); var toString = stream.Documents.Single().RootNode.ToString(); diff --git a/YamlDotNet/RepresentationModel/YamlMappingNode.cs b/YamlDotNet/RepresentationModel/YamlMappingNode.cs index 3aa34d9ad..b356f88c9 100644 --- a/YamlDotNet/RepresentationModel/YamlMappingNode.cs +++ b/YamlDotNet/RepresentationModel/YamlMappingNode.cs @@ -297,7 +297,9 @@ public override int GetHashCode() foreach (var entry in children) { hashCode = CombineHashCodes(hashCode, entry.Key); - hashCode = CombineHashCodes(hashCode, entry.Value); + hashCode = entry.Value.Anchor.IsEmpty + ? CombineHashCodes(hashCode, entry.Value) + : CombineHashCodes(hashCode, entry.Value.Anchor); } return hashCode; }