Skip to content

Commit 62b7f59

Browse files
authored
Merge pull request #964 from EdwardCooke/ec-mappingwithanchor
Fix single element with anchor inline mapping
2 parents 5240bf7 + 22fac65 commit 62b7f59

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

YamlDotNet.Test/Core/EventsHelper.cs

+13-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ protected ScalarBuilder PlainScalar(string text)
8787
return new ScalarBuilder(text, ScalarStyle.Plain);
8888
}
8989

90+
protected ScalarBuilder PlainScalar(string text, AnchorName anchor)
91+
{
92+
return new ScalarBuilder(text, ScalarStyle.Plain, anchor);
93+
}
94+
9095
protected ScalarBuilder SingleQuotedScalar(string text)
9196
{
9297
return new ScalarBuilder(text, ScalarStyle.SingleQuoted);
@@ -159,12 +164,19 @@ protected Comment InlineComment(string value)
159164

160165
protected class ScalarBuilder
161166
{
167+
private readonly AnchorName anchor = AnchorName.Empty;
162168
private readonly string text;
163169
private readonly ScalarStyle style;
164170
private string tag;
165171
private bool plainImplicit;
166172
private bool quotedImplicit;
167173

174+
public ScalarBuilder(string text, ScalarStyle style, AnchorName anchor)
175+
: this(text, style)
176+
{
177+
this.anchor = anchor;
178+
}
179+
168180
public ScalarBuilder(string text, ScalarStyle style)
169181
{
170182
this.text = text;
@@ -202,7 +214,7 @@ public ScalarBuilder ImplicitQuoted
202214

203215
public static implicit operator Scalar(ScalarBuilder builder)
204216
{
205-
return new Scalar(AnchorName.Empty,
217+
return new Scalar(builder.anchor,
206218
builder.tag,
207219
builder.text,
208220
builder.style,

YamlDotNet.Test/Core/ParserTests.cs

+14
Original file line numberDiff line numberDiff line change
@@ -455,5 +455,19 @@ public void NewLinesAreParsedAccordingToTheSpecification(string yaml, string exp
455455
DocumentEnd(Implicit),
456456
StreamEnd);
457457
}
458+
459+
[Fact]
460+
public void SingleElementeWithAnchorInlineMapping()
461+
{
462+
AssertSequenceOfEventsFrom(Yaml.ParserForText(@"{ key: &value value }"),
463+
StreamStart,
464+
DocumentStart(Implicit),
465+
FlowMappingStart,
466+
PlainScalar("key"),
467+
PlainScalar("value", "value"),
468+
MappingEnd,
469+
DocumentEnd(Implicit),
470+
StreamEnd);
471+
}
458472
}
459473
}

YamlDotNet/Core/Parser.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,8 @@ private ParsingEvent ParseNode(bool isBlock, bool isIndentlessSequence)
575575
}
576576

577577
// Read next token to ensure the error case spec test 'T833':
578-
// "Flow mapping missing a separating comma".
579578

580-
if (state == ParserState.FlowMappingKey && scanner.MoveNextWithoutConsuming())
579+
if (state == ParserState.FlowMappingKey && !(scanner.Current is FlowMappingEnd) && scanner.MoveNextWithoutConsuming())
581580
{
582581
currentToken = scanner.Current;
583582
if (currentToken != null && !(currentToken is FlowEntry) && !(currentToken is FlowMappingEnd))

0 commit comments

Comments
 (0)