Skip to content

Commit dacf87c

Browse files
authored
Merge pull request #780 from hemnstill/mergingparser_with_aliases
MergingParser deserializer can now handle nested NodeSequence + tests +semver:fix
2 parents f18356c + e9119dd commit dacf87c

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

YamlDotNet.Test/Serialization/DeserializerTest.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
using System;
2323
using System.Collections.Generic;
24+
using System.IO;
2425
using System.Linq;
2526
using FluentAssertions;
2627
using Xunit;
@@ -331,6 +332,42 @@ public void DeserializeWithoutDuplicateKeyChecking_YamlWithDuplicateKeys_DoesNot
331332
act = () => sut.Deserialize<Dictionary<string, Dictionary<string, string>>>(parser);
332333
act.ShouldNotThrow<YamlException>("Because duplicate key checking is not enabled");
333334
}
335+
336+
[Fact]
337+
public void MergingParserWithMergeObjectWithSequence_ShouldNotThrowException()
338+
{
339+
var yaml = @"
340+
base_level: &base
341+
tenant:
342+
- a1
343+
Level1: &Level1
344+
<<: [*base]
345+
Level2: &Level2
346+
<<: *Level1
347+
";
348+
var mergingParserFailed = new MergingParser(new Parser(new StringReader(yaml)));
349+
var deserializer = new DeserializerBuilder().Build();
350+
Action act = () => deserializer.Deserialize(mergingParserFailed);
351+
act.ShouldNotThrow<Exception>();
352+
}
353+
354+
[Fact]
355+
public void MergingParserWithNestedSequence_ShouldNotThrowException()
356+
{
357+
var yaml = @"
358+
base_level: &base {}
359+
Level1: &Level1
360+
<<: [*base]
361+
Level2: &Level2
362+
<<: [*Level1]
363+
Level3:
364+
<<: *Level2
365+
";
366+
var mergingParserFailed = new MergingParser(new Parser(new StringReader(yaml)));
367+
var deserializer = new DeserializerBuilder().Build();
368+
Action act = () => deserializer.Deserialize(mergingParserFailed);
369+
act.ShouldNotThrow<Exception>();
370+
}
334371

335372
public class Test
336373
{

YamlDotNet/Core/MergingParser.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ private bool HandleSequence(LinkedListNode<ParsingEvent> node)
140140
var current = node;
141141
while (current != null)
142142
{
143-
if (current.Value is SequenceEnd)
143+
if (current.Value is SequenceEnd &&
144+
current.Value.Start.Line >= sequenceStart.Value.Start.Line)
144145
{
145146
events.MarkDeleted(current);
146147
return true;

0 commit comments

Comments
 (0)