From e6d4d6c7a128744de7b2e79ac7c59bb5ec42a326 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Thu, 3 Mar 2016 12:34:17 -0800 Subject: [PATCH] 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 --- .../Parser/CSharpCodeParser.Statements.cs | 2 +- .../Parser/CSharp/CSharpBlockTest.cs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.AspNetCore.Razor/Parser/CSharpCodeParser.Statements.cs b/src/Microsoft.AspNetCore.Razor/Parser/CSharpCodeParser.Statements.cs index cfba20e469..6fc0b0bfa0 100644 --- a/src/Microsoft.AspNetCore.Razor/Parser/CSharpCodeParser.Statements.cs +++ b/src/Microsoft.AspNetCore.Razor/Parser/CSharpCodeParser.Statements.cs @@ -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; } } diff --git a/test/Microsoft.AspNetCore.Razor.Test/Parser/CSharp/CSharpBlockTest.cs b/test/Microsoft.AspNetCore.Razor.Test/Parser/CSharp/CSharpBlockTest.cs index 5c1c21633a..b46de748b0 100644 --- a/test/Microsoft.AspNetCore.Razor.Test/Parser/CSharp/CSharpBlockTest.cs +++ b/test/Microsoft.AspNetCore.Razor.Test/Parser/CSharp/CSharpBlockTest.cs @@ -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() {