From aaa14cd36b29b9f1ff3b4a07f47cd356edbc0fe7 Mon Sep 17 00:00:00 2001 From: Ajay Bhargav Baaskaran Date: Wed, 20 May 2015 12:50:30 -0700 Subject: [PATCH] More bug fix for #379 --- .../Parser/HtmlMarkupParser.Block.cs | 25 +++++++++++-------- .../Parser/CSharp/CSharpToMarkupSwitchTest.cs | 2 +- .../CS/Output/CodeBlockWithTextElement.cs | 9 +++---- .../CodeGenerator/CS/Output/ResolveUrl.cs | 10 ++------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs b/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs index 08f818c517..70e3fca0bb 100644 --- a/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs +++ b/src/Microsoft.AspNet.Razor/Parser/HtmlMarkupParser.Block.cs @@ -1049,19 +1049,22 @@ namespace Microsoft.AspNet.Razor.Parser tags.Clear(); if (!Context.DesignTimeMode) { - if (Context.LastSpan.Kind == SpanKind.Transition) + if (At(HtmlSymbolType.WhiteSpace)) { - // Output current span content as markup. - Output(SpanKind.Markup); + if (Context.LastSpan.Kind == SpanKind.Transition) + { + // Output current span content as markup. + Output(SpanKind.Markup); - // Accept and mark the whitespace at the end of a tag as code. - AcceptWhile(HtmlSymbolType.WhiteSpace); - Span.CodeGenerator = new StatementCodeGenerator(); - Output(SpanKind.Code); - } - else - { - AcceptWhile(HtmlSymbolType.WhiteSpace); + // Accept and mark the whitespace at the end of a tag as code. + AcceptWhile(HtmlSymbolType.WhiteSpace); + Span.CodeGenerator = new StatementCodeGenerator(); + Output(SpanKind.Code); + } + else + { + AcceptWhile(HtmlSymbolType.WhiteSpace); + } } if (!EndOfFile && CurrentSymbol.Type == HtmlSymbolType.NewLine) diff --git a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpToMarkupSwitchTest.cs b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpToMarkupSwitchTest.cs index a6167cd7fa..f71905d19a 100644 --- a/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpToMarkupSwitchTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/Parser/CSharp/CSharpToMarkupSwitchTest.cs @@ -647,7 +647,7 @@ namespace Microsoft.AspNet.Razor.Test.Parser.CSharp ), new MarkupTagBlock( Factory.MarkupTransition("").Accepts(AcceptedCharacters.None)), - Factory.Markup(Environment.NewLine).With(new StatementCodeGenerator()).Accepts(AcceptedCharacters.None) + Factory.Markup(Environment.NewLine).Accepts(AcceptedCharacters.None) ), Factory.Code($" }}{Environment.NewLine} if(!false) {{{Environment.NewLine}").AsStatement(), new MarkupBlock( diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/CodeBlockWithTextElement.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/CodeBlockWithTextElement.cs index e40a37c354..0415b68191 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/CodeBlockWithTextElement.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/CodeBlockWithTextElement.cs @@ -49,12 +49,9 @@ namespace TestOutput #line default #line hidden Instrumentation.EndContext(); -#line 3 "CodeBlockWithTextElement.cshtml" - - -#line default -#line hidden - + Instrumentation.BeginContext(80, 2, true); + WriteLiteral("\r\n"); + Instrumentation.EndContext(); #line 4 "CodeBlockWithTextElement.cshtml" #line default diff --git a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs index 71c1f8b2a7..db852f50d0 100644 --- a/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs +++ b/test/Microsoft.AspNet.Razor.Test/TestFiles/CodeGenerator/CS/Output/ResolveUrl.cs @@ -81,15 +81,9 @@ namespace TestOutput Instrumentation.EndContext(); WriteAttribute("href", Tuple.Create(" href=\"", 387), Tuple.Create("\"", 442), Tuple.Create(Tuple.Create("", 394), Tuple.Create(Href("~/A+Really(Crazy),Url.Is:This/"), 394), false), Tuple.Create(Tuple.Create("", 424), Tuple.Create(product.id, 424), false), Tuple.Create(Tuple.Create("", 435), Tuple.Create("/Detail", 435), true)); - Instrumentation.BeginContext(443, 21, true); - WriteLiteral(">Crazy Url!\r\n "); + Instrumentation.BeginContext(443, 23, true); + WriteLiteral(">Crazy Url!\r\n \r\n"); Instrumentation.EndContext(); -#line 12 "ResolveUrl.cshtml" - - -#line default -#line hidden - #line 13 "ResolveUrl.cshtml" #line default