-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Preserve quote style when rendering markup content #33548
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
Conversation
src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentMarkupBlockPass.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentMarkupBlockPass.cs
Show resolved
Hide resolved
…omponentMarkupBlockPass.cs Co-authored-by: campersau <[email protected]>
data-hs-header-options='{ this as an attribute on a normal html element (in this case ) is still causing problems. The content is coming up as null when I try to get the string from the attribute.
|
Hi @phlexpay. It looks like you just commented on a closed PR. The team will most probably miss it. If you'd like to bring something important up to their attention, consider filing a new issue and add enough details to build context. |
Fixes #20950.
When a component renders static markup like:
The Razor compiler interprets this collection of lines as a MarkupBlock. Unlike tag helper attributes, we don't store any information about what type of quote is used in the attributes (typically represented with an
AttributeStructure
enum). Instead, we indiscriminately use double quotes for all attributes on an HTML element within a markup block.aspnetcore/src/Razor/Microsoft.AspNetCore.Razor.Language/src/Components/ComponentMarkupBlockPass.cs
Lines 330 to 335 in 3d1c0e3
This causes issues in particular if a markup element like
<input onfocus='alert("Test");' />
is rendered because we produce the incorrectly quoted<input onfocus="alert("Test");" />
. To resolve this, we add a check when constructing the attribute string to preserve the original quote style designated by the user.