Skip to content

Razor compiler produces incorrect markup content for single-quoted attributes #20950

@SteveSandersonMS

Description

@SteveSandersonMS

Repro: Create a .razor file containing:

<button onclick='alert("hello")'>Click me</button>

Compiled result:

__builder.AddMarkupContent(0, "<button onclick=\"alert(\"hello\")\">Click me</button>");

This is incorrect because the double-quotes inside the attribute haven't been encoded in any way. At runtime, clicking on the button will produce an error (SyntaxError: Unexpected end of input).

Expected result: Something like

__builder.AddMarkupContent(0, "<button onclick=\"alert(&quot;hello&quot;)\">Click me</button>");

Or even:

__builder.AddMarkupContent(0, "<button onclick='alert(\"hello\")'>Click me</button>");

Do we claim to support single-quoted attributes fully in Razor?

cc @ajaybhargavb @NTaylorMullen

Metadata

Metadata

Assignees

No one assigned

    Labels

    affected-very-fewThis issue impacts very few customersarea-blazorIncludes: Blazor, Razor ComponentsbugThis issue describes a behavior which is not expected - a bug.feature-razor.languageseverity-nice-to-haveThis label is used by an internal tool

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions