Skip to content

Commit

Permalink
Fix single element with anchor inline mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwardCooke committed Sep 1, 2024
1 parent 5240bf7 commit 22fac65
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
14 changes: 13 additions & 1 deletion YamlDotNet.Test/Core/EventsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ protected ScalarBuilder PlainScalar(string text)
return new ScalarBuilder(text, ScalarStyle.Plain);
}

protected ScalarBuilder PlainScalar(string text, AnchorName anchor)
{
return new ScalarBuilder(text, ScalarStyle.Plain, anchor);
}

protected ScalarBuilder SingleQuotedScalar(string text)
{
return new ScalarBuilder(text, ScalarStyle.SingleQuoted);
Expand Down Expand Up @@ -159,12 +164,19 @@ protected Comment InlineComment(string value)

protected class ScalarBuilder
{
private readonly AnchorName anchor = AnchorName.Empty;
private readonly string text;
private readonly ScalarStyle style;
private string tag;
private bool plainImplicit;
private bool quotedImplicit;

public ScalarBuilder(string text, ScalarStyle style, AnchorName anchor)
: this(text, style)
{
this.anchor = anchor;
}

public ScalarBuilder(string text, ScalarStyle style)
{
this.text = text;
Expand Down Expand Up @@ -202,7 +214,7 @@ public ScalarBuilder ImplicitQuoted

public static implicit operator Scalar(ScalarBuilder builder)
{
return new Scalar(AnchorName.Empty,
return new Scalar(builder.anchor,
builder.tag,
builder.text,
builder.style,
Expand Down
14 changes: 14 additions & 0 deletions YamlDotNet.Test/Core/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -455,5 +455,19 @@ public void NewLinesAreParsedAccordingToTheSpecification(string yaml, string exp
DocumentEnd(Implicit),
StreamEnd);
}

[Fact]
public void SingleElementeWithAnchorInlineMapping()
{
AssertSequenceOfEventsFrom(Yaml.ParserForText(@"{ key: &value value }"),
StreamStart,
DocumentStart(Implicit),
FlowMappingStart,
PlainScalar("key"),
PlainScalar("value", "value"),
MappingEnd,
DocumentEnd(Implicit),
StreamEnd);
}
}
}
3 changes: 1 addition & 2 deletions YamlDotNet/Core/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,8 @@ private ParsingEvent ParseNode(bool isBlock, bool isIndentlessSequence)
}

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

if (state == ParserState.FlowMappingKey && scanner.MoveNextWithoutConsuming())
if (state == ParserState.FlowMappingKey && !(scanner.Current is FlowMappingEnd) && scanner.MoveNextWithoutConsuming())
{
currentToken = scanner.Current;
if (currentToken != null && !(currentToken is FlowEntry) && !(currentToken is FlowMappingEnd))
Expand Down

0 comments on commit 22fac65

Please sign in to comment.