Skip to content

Commit

Permalink
Fix handling nonvoid elements in markup blocks (#1190)
Browse files Browse the repository at this point in the history
* Fix empty nonvoid elements in markup blocks. Fixes #1186

* Also update another test
  • Loading branch information
SteveSandersonMS committed Jul 25, 2018
1 parent 0f8fdad commit 4e892e7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public void VisitExtension(HtmlElementIntermediateNode node)
}

// 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
Expand All @@ -209,8 +209,11 @@ public void VisitExtension(HtmlElementIntermediateNode node)
}
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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ public void SupportsSelfClosingElementsWithDynamicContent()
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,12 @@ public void Execute_RewritesHtml_CSharpInBody()
}

[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);

Expand Down

0 comments on commit 4e892e7

Please sign in to comment.