diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
index cbf0c1021a..4f4d710616 100644
--- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
+++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/HtmlMarkupParser.cs
@@ -856,7 +856,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
// Capture whitespace
var whitespace = ReadWhile(token => token.Type == HtmlTokenType.WhiteSpace || token.Type == HtmlTokenType.NewLine);
- if (At(HtmlTokenType.Transition))
+ if (At(HtmlTokenType.Transition) || At(HtmlTokenType.RazorCommentTransition))
{
// Transition outside of attribute value => Switch to recovery mode
Accept(whitespace);
@@ -931,7 +931,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
{
// First, determine if this is a 'data-' attribute (since those can't use conditional attributes)
var name = string.Concat(nameTokens.Select(s => s.Content));
- var attributeCanBeConditional =
+ var attributeCanBeConditional =
Context.FeatureFlags.EXPERIMENTAL_AllowConditionalDataDashAttributes ||
!name.StartsWith("data-", StringComparison.OrdinalIgnoreCase);
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs
index bcc8974b86..af280d67f0 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/Legacy/CSharpRazorCommentsTest.cs
@@ -42,6 +42,18 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
+ "}");
}
+ [Fact]
+ public void RazorCommentInOpeningTagBlock()
+ {
+ ParseDocumentTest("");
+ }
+
+ [Fact]
+ public void RazorCommentInClosingTagBlock()
+ {
+ ParseDocumentTest("");
+ }
+
[Fact]
public void UnterminatedRazorCommentInVerbatimBlock()
{
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml
index bd4820f914..1edd2fcc49 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml
@@ -13,3 +13,6 @@
But this should show the comment syntax: @bar
@(a@**@b)
+
+
+
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_DesignTime.ir.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_DesignTime.ir.txt
index e75591ec2d..5853591fb0 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_DesignTime.ir.txt
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_DesignTime.ir.txt
@@ -38,5 +38,14 @@ Document -
CSharpExpression - (323:14,2 [2] RazorComments.cshtml)
IntermediateToken - (323:14,2 [1] RazorComments.cshtml) - CSharp - a
IntermediateToken - (328:14,7 [1] RazorComments.cshtml) - CSharp - b
- HtmlContent - (330:14,9 [2] RazorComments.cshtml)
- IntermediateToken - (330:14,9 [2] RazorComments.cshtml) - Html - \n
+ HtmlContent - (330:14,9 [85] RazorComments.cshtml)
+ IntermediateToken - (330:14,9 [4] RazorComments.cshtml) - Html - \n\n
+ IntermediateToken - (334:16,0 [6] RazorComments.cshtml) - Html -
+ IntermediateToken - (406:16,72 [2] RazorComments.cshtml) - Html - \n
+ IntermediateToken - (408:17,0 [7] RazorComments.cshtml) - Html -
+ IntermediateToken - (473:17,65 [2] RazorComments.cshtml) - Html - \n
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.codegen.cs b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.codegen.cs
index d9b27a45c7..7579c50719 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.codegen.cs
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.codegen.cs
@@ -1,11 +1,11 @@
-#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "051345e2cc0313fea445db2f6cf48fe28b0b4edf"
+#pragma checksum "TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "4d553281e07fafc67ca0139b27ee95724a37f162"
//
#pragma warning disable 1591
[assembly: global::Microsoft.AspNetCore.Razor.Hosting.RazorCompiledItemAttribute(typeof(Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles.TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorComments_Runtime), @"default", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml")]
namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests.TestFiles
{
#line hidden
- [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"051345e2cc0313fea445db2f6cf48fe28b0b4edf", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml")]
+ [global::Microsoft.AspNetCore.Razor.Hosting.RazorSourceChecksumAttribute(@"SHA1", @"4d553281e07fafc67ca0139b27ee95724a37f162", @"/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments.cshtml")]
public class TestFiles_IntegrationTests_CodeGenerationIntegrationTest_RazorComments_Runtime
{
#pragma warning disable 1998
@@ -45,7 +45,8 @@ Write(ab);
#line default
#line hidden
- WriteLiteral("\r\n");
+ WriteLiteral("\r\n\r\n\r\n\r\n");
}
#pragma warning restore 1998
}
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.ir.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.ir.txt
index e05218677f..47c3a144f1 100644
--- a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.ir.txt
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/IntegrationTests/CodeGenerationIntegrationTest/RazorComments_Runtime.ir.txt
@@ -33,5 +33,14 @@ Document -
CSharpExpression - (323:14,2 [2] RazorComments.cshtml)
IntermediateToken - (323:14,2 [1] RazorComments.cshtml) - CSharp - a
IntermediateToken - (328:14,7 [1] RazorComments.cshtml) - CSharp - b
- HtmlContent - (330:14,9 [2] RazorComments.cshtml)
- IntermediateToken - (330:14,9 [2] RazorComments.cshtml) - Html - \n
+ HtmlContent - (330:14,9 [85] RazorComments.cshtml)
+ IntermediateToken - (330:14,9 [4] RazorComments.cshtml) - Html - \n\n
+ IntermediateToken - (334:16,0 [6] RazorComments.cshtml) - Html -
+ IntermediateToken - (406:16,72 [2] RazorComments.cshtml) - Html - \n
+ IntermediateToken - (408:17,0 [7] RazorComments.cshtml) - Html -
+ IntermediateToken - (473:17,65 [2] RazorComments.cshtml) - Html - \n
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInClosingTagBlock.cspans.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInClosingTagBlock.cspans.txt
new file mode 100644
index 0000000000..af3dd82d31
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInClosingTagBlock.cspans.txt
@@ -0,0 +1,8 @@
+Markup span at (0:0,0 [6] ) (Accepts:Any) - Parent: Tag block at (0:0,0 [6] )
+Markup span at (6:0,6 [7] ) (Accepts:Any) - Parent: Tag block at (6:0,6 [7] )
+Transition span at (13:0,13 [1] ) (Accepts:None) - Parent: Comment block at (13:0,13 [19] )
+MetaCode span at (14:0,14 [1] ) (Accepts:None) - Parent: Comment block at (13:0,13 [19] )
+Comment span at (15:0,15 [15] ) (Accepts:Any) - Parent: Comment block at (13:0,13 [19] )
+MetaCode span at (30:0,30 [1] ) (Accepts:None) - Parent: Comment block at (13:0,13 [19] )
+Transition span at (31:0,31 [1] ) (Accepts:None) - Parent: Comment block at (13:0,13 [19] )
+Markup span at (32:0,32 [1] ) (Accepts:Any) - Parent: Markup block at (0:0,0 [33] )
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInClosingTagBlock.stree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInClosingTagBlock.stree.txt
new file mode 100644
index 0000000000..4ac1dd74e2
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInClosingTagBlock.stree.txt
@@ -0,0 +1,25 @@
+Markup block - Gen - 33 - (0:0,0)
+ Tag block - Gen - 6 - (0:0,0)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (0:0,0) - Tokens:3
+ HtmlTokenType.OpenAngle;[<];
+ HtmlTokenType.Text;[text];
+ HtmlTokenType.CloseAngle;[>];
+ Tag block - Gen - 7 - (6:0,6)
+ Markup span - Gen - [ - 19 - (13:0,13)
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (13:0,13) - Tokens:1
+ HtmlTokenType.RazorCommentTransition;[@];
+ MetaCode span - Gen - [*] - SpanEditHandler;Accepts:None - (14:0,14) - Tokens:1
+ HtmlTokenType.RazorCommentStar;[*];
+ Comment span - Gen - [ razor comment ] - SpanEditHandler;Accepts:Any - (15:0,15) - Tokens:1
+ HtmlTokenType.RazorComment;[ razor comment ];
+ MetaCode span - Gen - [*] - SpanEditHandler;Accepts:None - (30:0,30) - Tokens:1
+ HtmlTokenType.RazorCommentStar;[*];
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (31:0,31) - Tokens:1
+ HtmlTokenType.RazorCommentTransition;[@];
+ Markup span - Gen - [>] - SpanEditHandler;Accepts:Any - (32:0,32) - Tokens:1
+ HtmlTokenType.CloseAngle;[>];
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInOpeningTagBlock.cspans.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInOpeningTagBlock.cspans.txt
new file mode 100644
index 0000000000..be8102eb0a
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInOpeningTagBlock.cspans.txt
@@ -0,0 +1,8 @@
+Markup span at (0:0,0 [6] ) (Accepts:Any) - Parent: Tag block at (0:0,0 [26] )
+Transition span at (6:0,6 [1] ) (Accepts:None) - Parent: Comment block at (6:0,6 [19] )
+MetaCode span at (7:0,7 [1] ) (Accepts:None) - Parent: Comment block at (6:0,6 [19] )
+Comment span at (8:0,8 [15] ) (Accepts:Any) - Parent: Comment block at (6:0,6 [19] )
+MetaCode span at (23:0,23 [1] ) (Accepts:None) - Parent: Comment block at (6:0,6 [19] )
+Transition span at (24:0,24 [1] ) (Accepts:None) - Parent: Comment block at (6:0,6 [19] )
+Markup span at (25:0,25 [1] ) (Accepts:Any) - Parent: Tag block at (0:0,0 [26] )
+Markup span at (26:0,26 [7] ) (Accepts:Any) - Parent: Tag block at (26:0,26 [7] )
diff --git a/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInOpeningTagBlock.stree.txt b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInOpeningTagBlock.stree.txt
new file mode 100644
index 0000000000..2b80249ac8
--- /dev/null
+++ b/test/Microsoft.AspNetCore.Razor.Language.Test/TestFiles/ParserTests/CSharpRazorCommentsTest/RazorCommentInOpeningTagBlock.stree.txt
@@ -0,0 +1,25 @@
+Markup block - Gen - 33 - (0:0,0)
+ Tag block - Gen - 26 - (0:0,0)
+ Markup span - Gen - [ - 19 - (6:0,6)
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (6:0,6) - Tokens:1
+ HtmlTokenType.RazorCommentTransition;[@];
+ MetaCode span - Gen - [*] - SpanEditHandler;Accepts:None - (7:0,7) - Tokens:1
+ HtmlTokenType.RazorCommentStar;[*];
+ Comment span - Gen - [ razor comment ] - SpanEditHandler;Accepts:Any - (8:0,8) - Tokens:1
+ HtmlTokenType.RazorComment;[ razor comment ];
+ MetaCode span - Gen - [*] - SpanEditHandler;Accepts:None - (23:0,23) - Tokens:1
+ HtmlTokenType.RazorCommentStar;[*];
+ Transition span - Gen - [@] - SpanEditHandler;Accepts:None - (24:0,24) - Tokens:1
+ HtmlTokenType.RazorCommentTransition;[@];
+ Markup span - Gen - [>] - SpanEditHandler;Accepts:Any - (25:0,25) - Tokens:1
+ HtmlTokenType.CloseAngle;[>];
+ Tag block - Gen - 7 - (26:0,26)
+ Markup span - Gen - [] - SpanEditHandler;Accepts:Any - (26:0,26) - Tokens:4
+ HtmlTokenType.OpenAngle;[<];
+ HtmlTokenType.ForwardSlash;[/];
+ HtmlTokenType.Text;[text];
+ HtmlTokenType.CloseAngle;[>];