Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
Expand Up @@ -50,4 +50,16 @@ public void WithUnfinishedTagAtEOFErrorsWithIncompleteTag()
{
ParseDocumentTest("@{<foo bar=baz");
}

[Fact]
public void EmptyOuterTagProducesErrorInMarkupBlock()
{
ParseDocumentTest("@{<>foo</>}");
}

[Fact]
public void EmptyOuterTagProducesErrorInTemplateExpression()
{
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): Error 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): Error 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): Error RZ1022: Outer tag is missing a name. The first character of a markup block must be an HTML tag with a valid name.
Copy link
Member

@davidwengier davidwengier Feb 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is introducing a new diagnostic into an existing test, that looks like this:

public void EmptyTag()
{
// This can happen in situations where a user is in VS' HTML editor and they're modifying
// the contents of an HTML tag.
ParseDocumentTest("@{<></> Bar}");
}

That doesn't seem like an issue to me, but feel free to disagree.

Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,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(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked and this method has no callers, before this PR. The diagnostic is never used 🤷‍♂️

new SourceSpan(tagStartLocation, contentLength: 1)));
}

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

var attributes = EmptySyntaxList;
Expand Down
Loading