Skip to content

Mark empty outer tags as errors when context switching from C# to markup (RZ1022)#12811

Open
Copilot wants to merge 3 commits intomainfrom
copilot/mark-empty-tags-as-errors
Open

Mark empty outer tags as errors when context switching from C# to markup (RZ1022)#12811
Copilot wants to merge 3 commits intomainfrom
copilot/mark-empty-tags-as-errors

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

Summary of the changes

@<>...</> used as a markup template transition compiles silently but throws a runtime InvalidCharacterError because <> is not a valid HTML element name. The parser already had RZ1022 ("Outer tag is missing a name") defined but never emitted it.

  • HtmlMarkupParser.ParseStartTag: Emit RZ1022 when the outermost tag of a MarkupInCodeBlock context has an empty name and is immediately closed (<>). The At(SyntaxKind.CloseAngle) guard ensures this only fires for <> and not for < at EOF, < with trailing whitespace, or < expr> patterns.
  • HtmlErrorTest: Two new tests covering @{<>foo</>} and @Html.Repeat(10, @<>Foo #@item</>).
  • Baseline updates: New .diag.txt baselines for the new tests in both test/TestFiles/ and legacyTest/TestFiles/; existing HtmlTagsTest.EmptyTag (@{<></> Bar}) in both test projects now correctly captures RZ1022.
Original prompt

This section details on the original issue you should resolve

<issue_title>empty tags should be marked as errors when context switching from c# to markup</issue_title>
<issue_description>yesterday i ran into this error

Image

because a coworker had created this code to make some rendering dynamic.

Image to force a context switch from c# to markup.

this (specifically, the empty tag in markup,
<>
should be marked as an error

this was my fix, btw: -

Image

i initially had a different variable name for the argument, but i got an error then, saying that __builder isn't declared - so i fixed it... feels a little like magic, but i can live with that :-P</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…kup (RZ1022)

Co-authored-by: davidwengier <754264+davidwengier@users.noreply.github.com>
Copilot AI changed the title [WIP] Mark empty tags as errors during context switching Mark empty outer tags as errors when context switching from C# to markup (RZ1022) Feb 22, 2026
Copilot AI requested a review from davidwengier February 22, 2026 20:07
@davidwengier
Copy link
Member

@copilot please investigate the test failures.

{
// 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 🤷‍♂️

Co-authored-by: davidwengier <754264+davidwengier@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Feb 22, 2026

@copilot please investigate the test failures.

The failure was in the legacy test project (Microsoft.AspNetCore.Razor.Language.Legacy.Test) — the HtmlTagsTest.EmptyTag test there was missing its .diag.txt baseline, since I'd only generated it for the main test/ project but not for legacyTest/. Fixed in da25b1e by adding legacyTest/TestFiles/ParserTests/HtmlTagsTest/EmptyTag.diag.txt.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • vb4vsblobprodcus33.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet test src/Compiler/Microsoft.AspNetCore.Razor.Language/legacyTest/Microsoft.AspNetCore.Razor.Language.Legacy.Test.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@@ -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.

@davidwengier davidwengier marked this pull request as ready for review February 22, 2026 23:08
@davidwengier davidwengier requested a review from a team as a code owner February 22, 2026 23:08
Copy link
Contributor

@ToddGrun ToddGrun left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Member

@chsienki chsienki left a comment

Choose a reason for hiding this comment

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

While I agree that this is the right fix, it's a breaking change. Sure, the code might have errored at runtime, but it did compile and if that code path was never executed it wouldn't have been an issue.

I don't think we can take this until we have warning waves (sigh)

@chsienki chsienki added the requires-warning-waves A feature or bug that would be a breaking change without warning waves label Feb 23, 2026
@davidwengier
Copy link
Member

if that code path was never executed it wouldn't have been an issue.

You're right :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

requires-warning-waves A feature or bug that would be a breaking change without warning waves

Projects

None yet

Development

Successfully merging this pull request may close these issues.

empty tags should be marked as errors when context switching from c# to markup

4 participants