Fix nested C# blocks when combined with C# @ symbols.

- We used to accept until markup or an ending brace which didn't allow the parser to balance nested braces.

#679
This commit is contained in:
N. Taylor Mullen 2016-03-03 12:34:17 -08:00
parent 38183b5887
commit e6d4d6c7a1
2 changed files with 15 additions and 1 deletions

View File

@ -654,7 +654,7 @@ namespace Microsoft.AspNetCore.Razor.Parser
{
Context.Source.Position = bookmark;
NextToken();
AcceptUntil(CSharpSymbolType.LessThan, CSharpSymbolType.RightBrace);
AcceptUntil(CSharpSymbolType.LessThan, CSharpSymbolType.LeftBrace, CSharpSymbolType.RightBrace);
return;
}
}

View File

@ -15,6 +15,20 @@ namespace Microsoft.AspNetCore.Razor.Test.Parser.CSharp
{
public class CSharpBlockTest : CsHtmlCodeParserTestBase
{
[Fact]
public void ParseBlock_NestedCodeBlockWithCSharpAt()
{
ParseBlockTest("{ if (true) { var val = @x; if (val != 3) { } } }",
new StatementBlock(
Factory.MetaCode("{").Accepts(AcceptedCharacters.None),
Factory
.Code(" if (true) { var val = @x; if (val != 3) { } } ")
.AsStatement()
.Accepts(AcceptedCharacters.Any)
.AutoCompleteWith(autoCompleteString: null, atEndOfSpan: false),
Factory.MetaCode("}").Accepts(AcceptedCharacters.None)));
}
[Fact]
public void ParseBlock_NestedCodeBlockWithMarkupSetsDotAsMarkup()
{