Skip to content

Commit

Permalink
Merge pull request #780 from hemnstill/mergingparser_with_aliases
Browse files Browse the repository at this point in the history
 MergingParser deserializer can now handle nested NodeSequence + tests

+semver:fix
  • Loading branch information
EdwardCooke authored Feb 19, 2023
2 parents f18356c + e9119dd commit dacf87c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
37 changes: 37 additions & 0 deletions YamlDotNet.Test/Serialization/DeserializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using FluentAssertions;
using Xunit;
Expand Down Expand Up @@ -331,6 +332,42 @@ public void DeserializeWithoutDuplicateKeyChecking_YamlWithDuplicateKeys_DoesNot
act = () => sut.Deserialize<Dictionary<string, Dictionary<string, string>>>(parser);
act.ShouldNotThrow<YamlException>("Because duplicate key checking is not enabled");
}

[Fact]
public void MergingParserWithMergeObjectWithSequence_ShouldNotThrowException()
{
var yaml = @"
base_level: &base
tenant:
- a1
Level1: &Level1
<<: [*base]
Level2: &Level2
<<: *Level1
";
var mergingParserFailed = new MergingParser(new Parser(new StringReader(yaml)));
var deserializer = new DeserializerBuilder().Build();
Action act = () => deserializer.Deserialize(mergingParserFailed);
act.ShouldNotThrow<Exception>();
}

[Fact]
public void MergingParserWithNestedSequence_ShouldNotThrowException()
{
var yaml = @"
base_level: &base {}
Level1: &Level1
<<: [*base]
Level2: &Level2
<<: [*Level1]
Level3:
<<: *Level2
";
var mergingParserFailed = new MergingParser(new Parser(new StringReader(yaml)));
var deserializer = new DeserializerBuilder().Build();
Action act = () => deserializer.Deserialize(mergingParserFailed);
act.ShouldNotThrow<Exception>();
}

public class Test
{
Expand Down
3 changes: 2 additions & 1 deletion YamlDotNet/Core/MergingParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ private bool HandleSequence(LinkedListNode<ParsingEvent> node)
var current = node;
while (current != null)
{
if (current.Value is SequenceEnd)
if (current.Value is SequenceEnd &&
current.Value.Start.Line >= sequenceStart.Value.Start.Line)
{
events.MarkDeleted(current);
return true;
Expand Down

0 comments on commit dacf87c

Please sign in to comment.