diff --git a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/HtmlBlockPass.cs b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/HtmlBlockPass.cs index b6371a39e2..7013888059 100644 --- a/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/HtmlBlockPass.cs +++ b/src/Microsoft.AspNetCore.Blazor.Razor.Extensions/HtmlBlockPass.cs @@ -200,7 +200,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor } // If for some reason a void element contains body, then treat it as a - // start/end tag. Treat non-void elements without body content as self-closing. + // start/end tag. if (!hasBodyContent && isVoid) { // void @@ -209,8 +209,11 @@ namespace Microsoft.AspNetCore.Blazor.Razor } else if (!hasBodyContent) { - // self-closing - Builder.Append("/>"); + // In HTML5, we can't have self-closing non-void elements, so explicitly + // add a close tag + Builder.Append(">"); return; } diff --git a/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs b/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs index ea3c613510..a63d078851 100644 --- a/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Build.Test/RenderingRazorIntegrationTest.cs @@ -147,12 +147,12 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test public void SupportsSelfClosingElementsAsStaticBlock() { // Arrange/Act - var component = CompileToComponent("Some text so elem isn't at position 0 "); + var component = CompileToComponent("Some text so elem isn't at position 0 "); // Assert Assert.Collection(GetRenderTree(component), frame => AssertFrame.Text(frame, "Some text so elem isn't at position 0 ", 0), - frame => AssertFrame.Markup(frame, "", 1)); + frame => AssertFrame.Markup(frame, "", 1)); } [Fact] diff --git a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/HtmlBlockPassTest.cs b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/HtmlBlockPassTest.cs index e8f36a824a..9d317ca1ff 100644 --- a/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/HtmlBlockPassTest.cs +++ b/test/Microsoft.AspNetCore.Blazor.Razor.Extensions.Test/HtmlBlockPassTest.cs @@ -109,12 +109,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor } [Fact] - public void Execute_RewritesHtml_SelfClosing() + public void Execute_RewritesHtml_EmptyNonvoid() { // Arrange var document = CreateDocument(@""); - var expected = NormalizeContent(@""); + var expected = NormalizeContent(@""); var documentNode = Lower(document);