Skip to content

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Feb 24, 2025

Quotes in attribute names are allowed by HTML spec. See https://html.spec.whatwg.org/multipage/parsing.html#attribute-name-state. Technically it's a parse error but the quote is still considered part of the attribute name and that's important here.

Previously, if razor saw a quote at the beginning of attribute name context, it would bail and consume everything until the matching quote. That's not how browsers parse that HTML - they consume the quote as part of the attribute name (and don't look for a matching quote). So this PR changes razor parser to do the same.

This fixes #11327 - the rest of the html after the misplaced quote is not stuffed into a "misc attribute" node as previously, but just the misplaced quote is parsed as an html attribute and then parsing continues normally, i.e., subsequent HTML elements are normally recognized, and tag helpers have effect on them, etc.

Visually:

<div class="test" "></div>
<!--              ^^^^^^^^ previously parsed as misc attribute -->
<!--              ^ now only this parsed as attribute, the rest parsed normally -->

No error is reported for the attribute named ". It looks like razor doesn't usually report errors for invalid HTML (especially such that browsers handle gracefully like here).

@jjonescz jjonescz added the area-compiler Umbrella for all compiler issues label Feb 24, 2025
@dotnet dotnet deleted a comment from azure-pipelines bot Feb 24, 2025
@jjonescz jjonescz marked this pull request as ready for review February 24, 2025 17:30
@jjonescz jjonescz requested a review from a team as a code owner February 24, 2025 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-compiler Umbrella for all compiler issues

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anchor tag helper is broken within foreach loop

3 participants