Skip to content

Commit

Permalink
adding test cases that cause recursive GetHashCode recursive call
Browse files Browse the repository at this point in the history
  • Loading branch information
barapiiro committed May 28, 2024
1 parent 2c57ca2 commit cc5f5a6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions YamlDotNet.Test/RepresentationModel/YamlStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,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<MaximumRecursionLevelReachedException>("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();

Expand Down

0 comments on commit cc5f5a6

Please sign in to comment.