Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix attribute parsing recovery #10620

Merged
merged 6 commits into from
Jul 19, 2024

Conversation

jjonescz
Copy link
Member

@jjonescz jjonescz commented Jul 15, 2024

Fixes #10586.

When a C# expression or a razor comment is encountered while parsing attributes, a recovery mode is entered but usually exited only at the end of the tag. That leads to parsing the remaining attributes inconsistently (the emitted code still usually works, but has a different codegen leading to the bug).

This PR changes that to parse C# expressions and razor comments and then exit the recovery mode and continue parsing attributes normally.

Note that this is not specific to conditional attributes per se but they best demonstrate the bug because in recovery mode they emit Write(null) whereas normally they emit WriteAttributeValue(null) which behaves differently (the latter omits the whole attribute).

This is also not a problem in Blazor components, they do not allow C# or razor comments in them, the @ is not a transition there but simply part of the attribute name (used for special attributes like @ref).

Commit-by-commit review might be useful.

@jjonescz jjonescz added the area-compiler Umbrella for all compiler issues label Jul 15, 2024
@jjonescz jjonescz marked this pull request as ready for review July 15, 2024 15:56
@jjonescz jjonescz requested review from a team as code owners July 15, 2024 15:56
Copy link
Member

@DustinCampbell DustinCampbell left a comment

Choose a reason for hiding this comment

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

I appreciate your excellent commit history! That made reviewing much easier.

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.

Conditional attribute rendering: null value attributes are sometimes unexpectedly rendered
5 participants