Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1,3): Warning RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Collections.Immutable;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.AspNetCore.Razor.Language;
Expand Down Expand Up @@ -91,6 +92,45 @@ public void Process_GeneratesCodeDocumentWithValidCSharpDocument()
Assert.Empty(csharpDocument.Diagnostics);
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12810")]
public void Process_EmptyOuterTag_DoesNotReportWarningAtRazorWarningLevel10()
{
// Arrange
var projectItem = new TestRazorProjectItem("Index.cshtml")
{
Content = "@{<>foo</>}"
};
var configuration = RazorConfiguration.Default with { RazorWarningLevel = 10 };
var projectEngine = RazorProjectEngine.Create(configuration, TestRazorProjectFileSystem.Empty);

// Act
var codeDocument = projectEngine.Process(projectItem);

// Assert
Assert.Empty(codeDocument.GetRequiredCSharpDocument().Diagnostics);
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12810")]
public void Process_EmptyOuterTag_ReportsWarningAtRazorWarningLevel11()
{
// Arrange
var projectItem = new TestRazorProjectItem("Index.cshtml")
{
Content = "@{<>foo</>}"
};
var configuration = RazorConfiguration.Default with { RazorWarningLevel = 11 };
var projectEngine = RazorProjectEngine.Create(configuration, TestRazorProjectFileSystem.Empty);

// Act
var codeDocument = projectEngine.Process(projectItem);

// Assert
var diagnostic = Assert.Single(codeDocument.GetRequiredCSharpDocument().Diagnostics);
Assert.Equal("RZ1022", diagnostic.Id);
Assert.Equal(RazorDiagnosticSeverity.Warning, diagnostic.Severity);
Assert.Equal(11, diagnostic.WarningLevel);
}

[Fact]
public void Process_WithImportsAndTagHelpers_SetsOnCodeDocument()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#nullable disable

using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.AspNetCore.Razor.Language.Legacy;
Expand Down Expand Up @@ -50,4 +51,16 @@ public void WithUnfinishedTagAtEOFErrorsWithIncompleteTag()
{
ParseDocumentTest("@{<foo bar=baz");
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12810")]
public void EmptyOuterTagProducesWarningInMarkupBlock()
{
ParseDocumentTest("@{<>foo</>}");
}

[Fact, WorkItem("https://github.com/dotnet/razor/issues/12810")]
public void EmptyOuterTagProducesWarningInTemplateExpression()
{
ParseDocumentTest("@Html.Repeat(10, @<>Foo #@item</>)");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [11] )
Transition span at (0:0,0 [1] ) - Parent: Statement block at (0:0,0 [11] )
MetaCode span at (1:0,1 [1] ) - Parent: Statement block at (0:0,0 [11] )
Markup span at (2:0,2 [2] ) - Parent: Tag block at (2:0,2 [2] )
Markup span at (4:0,4 [3] ) - Parent: Markup block at (2:0,2 [8] )
Markup span at (7:0,7 [3] ) - Parent: Tag block at (7:0,7 [3] )
Code span at (10:0,10 [0] ) - Parent: Statement block at (0:0,0 [11] )
MetaCode span at (10:0,10 [1] ) - Parent: Statement block at (0:0,0 [11] )
Markup span at (11:0,11 [0] ) - Parent: Markup block at (0:0,0 [11] )
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1,3): Warning RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
RazorDocument - [0..11)::11 - [@{<>foo</>}]
MarkupBlock - [0..11)::11
MarkupTextLiteral - [0..0)::0 - [] - Gen<Markup>
Marker;[];
CSharpCodeBlock - [0..11)::11
CSharpStatement - [0..11)::11
CSharpTransition - [0..1)::1 - Gen<None>
Transition;[@];
CSharpStatementBody - [1..11)::10
RazorMetaCode - [1..2)::1 - Gen<None>
LeftBrace;[{];
CSharpCodeBlock - [2..10)::8
MarkupBlock - [2..10)::8
MarkupElement - [2..10)::8
MarkupStartTag - [2..4)::2 - [<>] - Gen<Markup>
OpenAngle;[<];
Text;[<Missing>];
CloseAngle;[>];
MarkupTextLiteral - [4..7)::3 - [foo] - Gen<Markup>
Text;[foo];
MarkupEndTag - [7..10)::3 - [</>] - Gen<Markup>
OpenAngle;[<];
ForwardSlash;[/];
Text;[<Missing>];
CloseAngle;[>];
CSharpStatementLiteral - [10..10)::0 - [] - Gen<Stmt>
Marker;[];
RazorMetaCode - [10..11)::1 - Gen<None>
RightBrace;[}];
MarkupTextLiteral - [11..11)::0 - [] - Gen<Markup>
Marker;[];
EndOfFile;[];
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Markup span at (0:0,0 [0] ) - Parent: Markup block at (0:0,0 [34] )
Transition span at (0:0,0 [1] ) - Parent: Expression block at (0:0,0 [34] )
Code span at (1:0,1 [16] ) - Parent: Expression block at (0:0,0 [34] )
Transition span at (17:0,17 [1] ) - Parent: Markup block at (17:0,17 [16] )
Markup span at (18:0,18 [2] ) - Parent: Tag block at (18:0,18 [2] )
Markup span at (20:0,20 [5] ) - Parent: Markup block at (17:0,17 [16] )
Transition span at (25:0,25 [1] ) - Parent: Expression block at (25:0,25 [5] )
Code span at (26:0,26 [4] ) - Parent: Expression block at (25:0,25 [5] )
Markup span at (30:0,30 [3] ) - Parent: Tag block at (30:0,30 [3] )
Code span at (33:0,33 [1] ) - Parent: Expression block at (0:0,0 [34] )
Markup span at (34:0,34 [0] ) - Parent: Markup block at (0:0,0 [34] )
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1,19): Warning RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
RazorDocument - [0..34)::34 - [@Html.Repeat(10, @<>Foo #@item</>)]
MarkupBlock - [0..34)::34
MarkupTextLiteral - [0..0)::0 - [] - Gen<Markup>
Marker;[];
CSharpCodeBlock - [0..34)::34
CSharpImplicitExpression - [0..34)::34
CSharpTransition - [0..1)::1 - Gen<None>
Transition;[@];
CSharpImplicitExpressionBody - [1..34)::33
CSharpCodeBlock - [1..34)::33
CSharpExpressionLiteral - [1..17)::16 - [Html.Repeat(10, ] - Gen<Expr>
Identifier;[Html];
Dot;[.];
Identifier;[Repeat];
LeftParenthesis;[(];
NumericLiteral;[10];
Comma;[,];
Whitespace;[ ];
CSharpTemplateBlock - [17..33)::16
MarkupBlock - [17..33)::16
MarkupTransition - [17..18)::1 - Gen<None>
Transition;[@];
MarkupElement - [18..33)::15
MarkupStartTag - [18..20)::2 - [<>] - Gen<Markup>
OpenAngle;[<];
Text;[<Missing>];
CloseAngle;[>];
MarkupTextLiteral - [20..25)::5 - [Foo #] - Gen<Markup>
Text;[Foo];
Whitespace;[ ];
Text;[#];
CSharpCodeBlock - [25..30)::5
CSharpImplicitExpression - [25..30)::5
CSharpTransition - [25..26)::1 - Gen<None>
Transition;[@];
CSharpImplicitExpressionBody - [26..30)::4
CSharpCodeBlock - [26..30)::4
CSharpExpressionLiteral - [26..30)::4 - [item] - Gen<Expr>
Identifier;[item];
MarkupEndTag - [30..33)::3 - [</>] - Gen<Markup>
OpenAngle;[<];
ForwardSlash;[/];
Text;[<Missing>];
CloseAngle;[>];
CSharpExpressionLiteral - [33..34)::1 - [)] - Gen<Expr>
RightParenthesis;[)];
MarkupTextLiteral - [34..34)::0 - [] - Gen<Markup>
Marker;[];
EndOfFile;[];
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(1,3): Warning RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name.
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,17 @@ private MarkupStartTagSyntax ParseStartTag(
return ParseStartTextTag(openAngleToken, out tagMode, out isWellFormed);
}

if (mode == ParseMode.MarkupInCodeBlock &&
_tagTracker.Count == 0 &&
tagName.Length == 0 &&
At(SyntaxKind.CloseAngle))
{
// The outer tag of a markup block is missing a name.
Context.ErrorSink.OnError(
RazorDiagnosticFactory.CreateParsing_OuterTagMissingName(
new SourceSpan(tagStartLocation, contentLength: 1)));
}

var tagNameToken = At(SyntaxKind.Text) ? EatCurrentToken() : SyntaxFactory.MissingToken(SyntaxKind.Text);

var attributes = EmptySyntaxList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ public static RazorDiagnostic CreateParsing_MarkupBlockMustStartWithTag(SourceSp
internal static readonly RazorDiagnosticDescriptor Parsing_OuterTagMissingName =
new($"{DiagnosticPrefix}1022",
Resources.ParseError_OuterTagMissingName,
RazorDiagnosticSeverity.Error);
RazorDiagnosticSeverity.Warning,
warningLevel: 11);

public static RazorDiagnostic CreateParsing_OuterTagMissingName(SourceSpan location)
=> RazorDiagnostic.Create(Parsing_OuterTagMissingName, location);
Expand Down
Loading