Fix handling nonvoid elements in markup blocks (#1190)

* Fix empty nonvoid elements in markup blocks. Fixes #1186

* Also update another test
This commit is contained in:
Steve Sanderson 2018-07-25 09:53:32 -07:00
parent 0f8fdad593
commit 4e892e74da
3 changed files with 10 additions and 7 deletions

View File

@ -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("></");
Builder.Append(node.TagName);
Builder.Append(">");
return;
}

View File

@ -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 <myelem />");
var component = CompileToComponent("Some text so elem isn't at position 0 <input attr='123' />");
// Assert
Assert.Collection(GetRenderTree(component),
frame => AssertFrame.Text(frame, "Some text so elem isn't at position 0 ", 0),
frame => AssertFrame.Markup(frame, "<myelem/>", 1));
frame => AssertFrame.Markup(frame, "<input attr=\"123\">", 1));
}
[Fact]

View File

@ -109,12 +109,12 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
[Fact]
public void Execute_RewritesHtml_SelfClosing()
public void Execute_RewritesHtml_EmptyNonvoid()
{
// Arrange
var document = CreateDocument(@"<a href=""...""></a>");
var expected = NormalizeContent(@"<a href=""...""/>");
var expected = NormalizeContent(@"<a href=""...""></a>");
var documentNode = Lower(document);