Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 16, 2026

Summary of the changes

HTML entities in Blazor component attributes were decoded inconsistently. Static attributes like <h1 title="Nice&trade;"> had entities decoded to during HTML parsing, while mixed attributes like <h1 title="Nice&trade; @DateTime.Now"> preserved the raw &trade; entity.

Extended ComponentMarkupEncodingPass to decode HTML entities in attribute values at compile time:

  • Added VisitHtmlAttributeValue override to decode entities in HtmlIntermediateToken children
  • Reuses existing TryDecodeHtmlEntities helper that handles both named entities (&trade;) and numeric entities (&#8482;, &#x2122;)
  • Preserves unknown/invalid entities unchanged (e.g., &invalid;)
  • Applies decoding uniformly to both static and mixed attribute content

This ensures tooltips, data attributes, and other attribute values display consistently regardless of whether they contain dynamic expressions.

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:

  • bcnvsblobprodcus378.vsblob.vsassets.io
    • Triggering command: /usr/share/dotnet/dotnet dotnet test src/Compiler/Microsoft.AspNetCore.Razor.Language/test/Microsoft.AspNetCore.Razor.Language.Test.csproj --filter FullyQualifiedName~ComponentMarkupEncodingPassTest --no-build --verbosity normal (dns block)

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

Original prompt

This section details on the original issue you should resolve

<issue_title>Inconsistency in HTML entities in attributes in .razor files</issue_title>
<issue_description>Compare the following:

<h1 title="This is nice&trade;">A</h1>
<h1 title="This is nice&trade;">B @DateTime.Now</h1>

In the first case, the tooltip displays This is nice™, whereas in the second case it displays This is nice&trade;.

The reason for the difference is that, when we introduce the element as markup, it goes through the HTML parser which implicitly converts &trade; to , whereas when we build the element dynamically we assign the attribute value using setAttribute which assumes the value already contains the desired, unencoded string.

As far as I'm aware, this only applies to HTML entities, and not to any other syntax such as embedding elements or comments inside attribute values, since those latter cases aren't actually valid.

I'm not certain what the desired solution would be. We definitely don't want to run literally all attribute values through the full HTML parser at runtime each time we set an attribute value, partly because perf and partly because we don't actually want a "full HTML parser" - we just want an "HTML entities to unicode" converter.

We might want something like:

  • For string literals in the source, perform HTML-entity-to-unicode conversion during compilation
  • For dynamic values at runtime, leave the existing behavior so it's equivalent to MVC/Razor Pages which proactively encode the attribute value before emitting it

We also need to check that prerendering produces the same effect as whatever we choose.</issue_description>

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

@ We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our [Triage Process](https://github.com/dotnet/aspnetcore/blob/master/docs/TriageProcess.md).

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

@dbreshears dbreshears assigned chsienki and unassigned dbreshears Jan 16, 2026
Copilot AI changed the title [WIP] Fix inconsistency in HTML entities in attributes of .razor files Fix HTML entity decoding inconsistency in Blazor component attributes Jan 16, 2026
Copilot AI requested a review from dbreshears January 16, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inconsistency in HTML entities in attributes in .razor files

3 participants