Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix single element with anchor inline mapping #964

Merged
merged 1 commit into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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