Skip to content

Commit 40e05a2

Browse files
authored
Merge pull request #759 from EdwardCooke/ec-fix-757
Allow braces in non-flows
2 parents 6bf5b44 + cca792b commit 40e05a2

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

YamlDotNet.Test/Core/ScannerTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,35 @@ public void Issue_553_562()
414414
}
415415
}
416416

417+
[Fact]
418+
public void Plain_Scalar_outside_of_flow_allows_braces()
419+
{
420+
AssertSequenceOfTokensFrom(Yaml.ScannerForText(@"value: -[123]"),
421+
StreamStart,
422+
BlockMappingStart,
423+
Key,
424+
PlainScalar("value"),
425+
Value,
426+
PlainScalar("-[123]"),
427+
BlockEnd,
428+
StreamEnd);
429+
}
430+
431+
[Fact]
432+
public void Plain_Scalar_inside_flow_does_not_allow_braces()
433+
{
434+
AssertPartialSequenceOfTokensFrom(Yaml.ScannerForText(@"
435+
[
436+
value: -[123]
437+
]"),
438+
StreamStart,
439+
FlowSequenceStart,
440+
Key,
441+
PlainScalar("value"),
442+
Value,
443+
Error("Invalid key indicator format."));
444+
}
445+
417446
private void AssertPartialSequenceOfTokensFrom(Scanner scanner, params Token[] tokens)
418447
{
419448
var tokenNumber = 1;

YamlDotNet.Test/Core/TokenHelper.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ protected static AnchorAlias AnchorAlias(string alias)
151151
return new AnchorAlias(new AnchorName(alias));
152152
}
153153

154+
protected static Error Error(string value)
155+
{
156+
return new Error(value, new Mark(), new Mark());
157+
}
158+
154159
protected static Comment StandaloneComment(string text)
155160
{
156161
return new Comment(text, false);

YamlDotNet/Core/Scanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private void FetchNextToken()
398398
FetchBlockEntry();
399399
return;
400400
}
401-
else if (analyzer.Check(",[]{}", 1))
401+
else if (flowLevel > 0 && analyzer.Check(",[]{}", 1))
402402
{
403403
tokens.Enqueue(new Error("Invalid key indicator format.", cursor.Mark(), cursor.Mark()));
404404
}

YamlDotNet/Core/Tokens/Error.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@
2222
namespace YamlDotNet.Core.Tokens
2323
{
2424
/// <summary>
25-
/// Base class for YAML tokens.
25+
/// Error tokens.
2626
/// </summary>
27-
internal class Error : Token
27+
public class Error : Token
2828
{
2929
/// <summary>
30-
/// Gets the value of the comment
30+
/// Gets the value of the error
3131
/// </summary>
32-
internal string Value { get; }
32+
public string Value { get; }
3333

34-
internal Error(string value, Mark start, Mark end)
34+
public Error(string value, Mark start, Mark end)
3535
: base(start, end)
3636
{
3737
Value = value;

0 commit comments

Comments
 (0)