Reenable markup blocks (#1286)

* Reenable HtmlBlock unit tests

* Add E2E tests for HTML Block cases

* Remove harded GenerateBaselines=true

* Fix #1193

This commit addresses the root cause of #1193. When we merge HTML
text nodes into HTML blocks we need to re-encode any HTML entities that
were encoded eariler.

I did a bit of a deep dive on how HTML encoding is handled in Blazor and
I think this is the best strategy. I think it's valuable that the
BrowserRenderer uses document.createTextNode, which will always encode
the text - this handles dynamic content. We want to keep this in place
to avoid HTML injection attacks.

* Fix #1265 Reenable MarkupBlock

* test cleanup
This commit is contained in:
Ryan Nowak 2018-08-10 16:29:39 -07:00 committed by GitHub
parent 70a4bf7521
commit a05cb42845
36 changed files with 185 additions and 110 deletions

View File

@ -79,9 +79,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
builder.Features.Add(new EventHandlerLoweringPass());
builder.Features.Add(new RefLoweringPass());
builder.Features.Add(new BindLoweringPass());
// Temporarily disabled for 0.5.1
// builder.Features.Add(new HtmlBlockPass());
builder.Features.Add(new HtmlBlockPass());
builder.Features.Add(new ComponentTagHelperDescriptorProvider());
builder.Features.Add(new BindTagHelperDescriptorProvider());

View File

@ -414,6 +414,13 @@ namespace Microsoft.AspNetCore.Blazor.Razor
throw new InvalidOperationException("You need to call Push first.");
}
// This will decode any HTML entities into their textual equivalent.
//
// This is OK because an HtmlContent node is used with document.createTextNode
// in the DOM, which can accept content that has decoded entities.
//
// In the event that we merge HtmlContent into an HtmlBlock, we need to
// re-encode the entites. That's done in the HtmlBlock pass.
var tokens = _textSource.Tokenize(HtmlEntityService.Resolver);
return tokens;
}

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AngleSharp.Html;
using Microsoft.AspNetCore.Razor.Language;
using Microsoft.AspNetCore.Razor.Language.Intermediate;
@ -166,11 +167,15 @@ namespace Microsoft.AspNetCore.Blazor.Razor
IntermediateNodeWalker,
IExtensionIntermediateNodeVisitor<HtmlElementIntermediateNode>
{
private readonly StringBuilder _encodingBuilder;
private readonly List<IntermediateNodeReference> _trees;
public RewriteVisitor(List<IntermediateNodeReference> trees)
{
_trees = trees;
_encodingBuilder = new StringBuilder();
}
public StringBuilder Builder { get; } = new StringBuilder();
@ -251,19 +256,28 @@ namespace Microsoft.AspNetCore.Blazor.Razor
public override void VisitHtmlAttributeValue(HtmlAttributeValueIntermediateNode node)
{
// Visit Children
base.VisitDefault(node);
Builder.Append(Encode(node.Children));
}
public override void VisitHtml(HtmlContentIntermediateNode node)
{
// Visit Children
base.VisitDefault(node);
Builder.Append(Encode(node.Children));
}
public override void VisitToken(IntermediateToken node)
private string Encode(IntermediateNodeCollection nodes)
{
Builder.Append(node.Content);
// We need to HTML encode text content. We would have decoded HTML entities
// earlier when we parsed the text into a tree, but since we're folding
// this node into a block of pre-encoded HTML we need to be sure to
// re-encode.
_encodingBuilder.Clear();
for (var i = 0; i < nodes.Count; i++)
{
_encodingBuilder.Append(((IntermediateToken)nodes[i]).Content);
}
return HtmlMarkupFormatter.Instance.Text(_encodingBuilder.ToString());
}
}
}

View File

@ -472,5 +472,21 @@ namespace Test
frame => AssertFrame.Attribute(frame, "onmouseover", 1),
frame => AssertFrame.Attribute(frame, "style", "background: #FFFFFF;", 2));
}
// Text nodes decode HTML entities
[Fact]
public void Render_Component_HtmlEncoded()
{
// Arrange
var component = CompileToComponent(@"&lt;span&gt;Hi&lt/span&gt;");
// Act
var frames = GetRenderTree(component);
// Assert
Assert.Collection(
frames,
frame => AssertFrame.Text(frame, "<span>Hi</span>"));
}
}
}

View File

@ -1256,7 +1256,6 @@ namespace Test
[Fact] // We don't process <!DOCTYPE ...> - we just skip them
public void Component_WithDocType()
{
GenerateBaselines = true;
// Arrange
// Act

View File

@ -19,10 +19,7 @@ namespace Test
builder.AddAttribute(1, "MyAttr", "abc");
builder.AddAttribute(2, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
builder2.AddContent(3, "Some text");
builder2.OpenElement(4, "some-child");
builder2.AddAttribute(5, "a", "1");
builder2.AddContent(6, "Nested text");
builder2.CloseElement();
builder2.AddMarkupContent(4, "<some-child a=\"1\">Nested text</some-child>");
}
));
builder.CloseComponent();

View File

@ -13,12 +13,7 @@ Document -
ComponentExtensionNode - (31:1,0 [91] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
HtmlContent - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (57:1,26 [9] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Some text
HtmlElement - (66:1,35 [42] x:\dir\subdir\Test\TestComponent.cshtml) - some-child
HtmlAttribute - - -
HtmlAttributeValue - -
IntermediateToken - - Html - 1
HtmlContent - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (84:1,53 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Nested text
HtmlBlock - - <some-child a="1">Nested text</some-child>
ComponentAttributeExtensionNode - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - MyAttr - MyAttr
HtmlContent - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (52:1,21 [3] x:\dir\subdir\Test\TestComponent.cshtml) - Html - abc

View File

@ -17,9 +17,7 @@ namespace Test
base.BuildRenderTree(builder);
builder.OpenComponent<Test.MyComponent>(0);
builder.AddAttribute(1, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
builder2.OpenElement(2, "child");
builder2.AddContent(3, "hello");
builder2.CloseElement();
builder2.AddMarkupContent(2, "<child>hello</child>");
}
));
builder.CloseComponent();

View File

@ -11,6 +11,4 @@ Document -
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
ComponentExtensionNode - (31:1,0 [47] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
HtmlElement - (44:1,13 [20] x:\dir\subdir\Test\TestComponent.cshtml) - child
HtmlContent - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (51:1,20 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - hello
HtmlBlock - - <child>hello</child>

View File

@ -15,9 +15,7 @@ namespace Test
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "div");
builder.AddContent(1, "\n");
builder.CloseElement();
builder.AddMarkupContent(0, "<div>\n</div>");
}
#pragma warning restore 1998
}

View File

@ -10,6 +10,4 @@ Document -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (17:1,0 [13] x:\dir\subdir\Test\TestComponent.cshtml) - div
HtmlContent - (22:1,5 [2] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (22:1,5 [2] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n
HtmlBlock - - <div>\n</div>

View File

@ -19,13 +19,11 @@ namespace Test
builder.AddAttribute(1, "SomeProp", "val");
builder.AddAttribute(2, "ChildContent", (Microsoft.AspNetCore.Blazor.RenderFragment)((builder2) => {
builder2.AddContent(3, "\n Some ");
builder2.OpenElement(4, "el");
builder2.AddContent(5, "further");
builder2.CloseElement();
builder2.AddContent(6, " content\n");
builder2.AddMarkupContent(4, "<el>further</el>");
builder2.AddContent(5, " content\n");
}
));
builder.AddComponentReferenceCapture(7, (__value) => {
builder.AddComponentReferenceCapture(6, (__value) => {
#line 2 "x:\dir\subdir\Test\TestComponent.cshtml"
myInstance = (Test.MyComponent)__value;

View File

@ -13,9 +13,7 @@ Document -
ComponentExtensionNode - (31:1,0 [96] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent - Test.MyComponent
HtmlContent - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (76:1,45 [11] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n Some
HtmlElement - (87:2,9 [16] x:\dir\subdir\Test\TestComponent.cshtml) - el
HtmlContent - (91:2,13 [7] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (91:2,13 [7] x:\dir\subdir\Test\TestComponent.cshtml) - Html - further
HtmlBlock - - <el>further</el>
HtmlContent - (103:2,25 [10] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (103:2,25 [10] x:\dir\subdir\Test\TestComponent.cshtml) - Html - content\n
RefExtensionNode - (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml) - myInstance - Test.MyComponent

View File

@ -1,13 +1,13 @@
Source Location: (49:1,18 [10] x:\dir\subdir\Test\TestComponent.cshtml)
|myInstance|
Generated Location: (1251:30,18 [10] )
Generated Location: (1176:28,18 [10] )
|myInstance|
Source Location: (143:5,12 [44] x:\dir\subdir\Test\TestComponent.cshtml)
|
private Test.MyComponent myInstance;
|
Generated Location: (1505:40,12 [44] )
Generated Location: (1430:38,12 [44] )
|
private Test.MyComponent myInstance;
|

View File

@ -17,9 +17,7 @@ namespace Test
base.BuildRenderTree(builder);
builder.AddContent(0, "My value");
builder.AddContent(1, "\n\n");
builder.OpenElement(2, "h1");
builder.AddContent(3, "Hello");
builder.CloseElement();
builder.AddMarkupContent(2, "<h1>Hello</h1>");
}
#pragma warning restore 1998
}

View File

@ -14,6 +14,4 @@ Document -
IntermediateToken - (2:0,2 [10] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - "My value"
HtmlContent - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (13:0,13 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlElement - (17:2,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlBlock - - <h1>Hello</h1>

View File

@ -18,9 +18,7 @@ namespace Test
builder.OpenComponent<Test.SomeOtherComponent>(0);
builder.CloseComponent();
builder.AddContent(1, "\n\n");
builder.OpenElement(2, "h1");
builder.AddContent(3, "Hello");
builder.CloseElement();
builder.AddMarkupContent(2, "<h1>Hello</h1>");
}
#pragma warning restore 1998
}

View File

@ -13,6 +13,4 @@ Document -
ComponentExtensionNode - (36:2,0 [22] x:\dir\subdir\Test\TestComponent.cshtml) - SomeOtherComponent - Test.SomeOtherComponent
HtmlContent - (58:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (58:2,22 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
HtmlElement - (62:4,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (66:4,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (66:4,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlBlock - - <h1>Hello</h1>

View File

@ -15,9 +15,7 @@ namespace Test
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "h1");
builder.AddContent(1, "Hello");
builder.CloseElement();
builder.AddMarkupContent(0, "<h1>Hello</h1>");
}
#pragma warning restore 1998
}

View File

@ -10,6 +10,4 @@ Document -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (17:2,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (21:2,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlBlock - - <h1>Hello</h1>

View File

@ -16,12 +16,10 @@ namespace Test
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "h1");
builder.AddContent(1, "Hello, world!");
builder.CloseElement();
builder.AddContent(2, "\n\nWelcome to your new app.\n\n");
builder.OpenComponent<Test.SurveyPrompt>(3);
builder.AddAttribute(4, "Title", "");
builder.AddMarkupContent(0, "<h1>Hello, world!</h1>");
builder.AddContent(1, "\n\nWelcome to your new app.\n\n");
builder.OpenComponent<Test.SurveyPrompt>(2);
builder.AddAttribute(3, "Title", "");
builder.CloseComponent();
}
#pragma warning restore 1998

View File

@ -11,9 +11,7 @@ Document -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (44:3,0 [22] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (48:3,4 [13] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (48:3,4 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello, world!
HtmlBlock - - <h1>Hello, world!</h1>
HtmlContent - (66:3,22 [32] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (66:3,22 [32] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\nWelcome to your new app.\n\n
ComponentExtensionNode - (98:7,0 [23] x:\dir\subdir\Test\TestComponent.cshtml) - SurveyPrompt - Test.SurveyPrompt

View File

@ -16,12 +16,10 @@ namespace Test
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "h1");
builder.AddContent(1, "Hello, world!");
builder.CloseElement();
builder.AddContent(2, "\n\nWelcome to your new app.\n\n");
builder.OpenComponent<Test.SurveyPrompt>(3);
builder.AddAttribute(4, "Title", "<div>Test!</div>");
builder.AddMarkupContent(0, "<h1>Hello, world!</h1>");
builder.AddContent(1, "\n\nWelcome to your new app.\n\n");
builder.OpenComponent<Test.SurveyPrompt>(2);
builder.AddAttribute(3, "Title", "<div>Test!</div>");
builder.CloseComponent();
}
#pragma warning restore 1998

View File

@ -11,9 +11,7 @@ Document -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (44:3,0 [22] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (48:3,4 [13] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (48:3,4 [13] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello, world!
HtmlBlock - - <h1>Hello, world!</h1>
HtmlContent - (66:3,22 [32] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (66:3,22 [32] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\nWelcome to your new app.\n\n
ComponentExtensionNode - (98:7,0 [41] x:\dir\subdir\Test\TestComponent.cshtml) - SurveyPrompt - Test.SurveyPrompt

View File

@ -15,11 +15,9 @@ namespace Test
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "h1");
builder.AddContent(1, "Hello");
builder.CloseElement();
builder.AddContent(2, "\n\n");
builder.AddContent(3, "My value");
builder.AddMarkupContent(0, "<h1>Hello</h1>");
builder.AddContent(1, "\n\n");
builder.AddContent(2, "My value");
}
#pragma warning restore 1998
}

View File

@ -10,9 +10,7 @@ Document -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (0:0,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlBlock - - <h1>Hello</h1>
HtmlContent - (14:0,14 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (14:0,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
CSharpExpression - (20:2,2 [10] x:\dir\subdir\Test\TestComponent.cshtml)

View File

@ -15,11 +15,9 @@ namespace Test
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "h1");
builder.AddContent(1, "Hello");
builder.CloseElement();
builder.AddContent(2, "\n\n");
builder.OpenComponent<Test.SomeOtherComponent>(3);
builder.AddMarkupContent(0, "<h1>Hello</h1>");
builder.AddContent(1, "\n\n");
builder.OpenComponent<Test.SomeOtherComponent>(2);
builder.CloseComponent();
}
#pragma warning restore 1998

View File

@ -10,9 +10,7 @@ Document -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (31:1,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (35:1,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (35:1,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlBlock - - <h1>Hello</h1>
HtmlContent - (45:1,14 [4] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (45:1,14 [4] x:\dir\subdir\Test\TestComponent.cshtml) - Html - \n\n
ComponentExtensionNode - (49:3,0 [22] x:\dir\subdir\Test\TestComponent.cshtml) - SomeOtherComponent - Test.SomeOtherComponent

View File

@ -16,9 +16,7 @@ namespace Test
protected override void BuildRenderTree(Microsoft.AspNetCore.Blazor.RenderTree.RenderTreeBuilder builder)
{
base.BuildRenderTree(builder);
builder.OpenElement(0, "h1");
builder.AddContent(1, "Hello");
builder.CloseElement();
builder.AddMarkupContent(0, "<h1>Hello</h1>");
}
#pragma warning restore 1998
}

View File

@ -11,6 +11,4 @@ Document -
MethodDeclaration - - protected override - void - BuildRenderTree
CSharpCode -
IntermediateToken - - CSharp - base.BuildRenderTree(builder);
HtmlElement - (0:0,0 [14] x:\dir\subdir\Test\TestComponent.cshtml) - h1
HtmlContent - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml)
IntermediateToken - (4:0,4 [5] x:\dir\subdir\Test\TestComponent.cshtml) - Html - Hello
HtmlBlock - - <h1>Hello</h1>

View File

@ -156,6 +156,53 @@ namespace Microsoft.AspNetCore.Blazor.E2ETest.Tests
Assert.Equal("somevalue", styledElement.GetAttribute("customattribute"));
}
// Verifies we can render HTML content as a single block
[Fact]
public void CanRenderChildContent_StaticHtmlBlock()
{
var appElement = MountTestComponent<HtmlBlockChildContent>();
Assert.Equal("<p>Some-Static-Text</p>",
appElement.FindElement(By.Id("foo")).GetAttribute("innerHTML"));
}
// Verifies we can rewite more complex HTML content into blocks
[Fact]
public void CanRenderChildContent_MixedHtmlBlock()
{
var appElement = MountTestComponent<HtmlMixedChildContent>();
var one = appElement.FindElement(By.Id("one"));
Assert.Equal("<p>Some-Static-Text</p>", one.GetAttribute("innerHTML"));
var two = appElement.FindElement(By.Id("two"));
Assert.Equal("<span>More-Static-Text</span>", two.GetAttribute("innerHTML"));
var three = appElement.FindElement(By.Id("three"));
Assert.Equal("Some-Dynamic-Text", three.GetAttribute("innerHTML"));
var four = appElement.FindElement(By.Id("four"));
Assert.Equal("But this is static", four.GetAttribute("innerHTML"));
}
// Verifies we can rewrite HTML blocks with encoded HTML
[Fact]
public void CanRenderChildContent_EncodedHtmlInBlock()
{
var appElement = MountTestComponent<HtmlEncodedChildContent>();
var one = appElement.FindElement(By.Id("one"));
Assert.Equal("<p>Some-Static-Text</p>", one.GetAttribute("innerHTML"));
var two = appElement.FindElement(By.Id("two"));
Assert.Equal("&lt;span&gt;More-Static-Text&lt;/span&gt;", two.GetAttribute("innerHTML"));
var three = appElement.FindElement(By.Id("three"));
Assert.Equal("Some-Dynamic-Text", three.GetAttribute("innerHTML"));
var four = appElement.FindElement(By.Id("four"));
Assert.Equal("But this is static", four.GetAttribute("innerHTML"));
}
[Fact]
public void CanTriggerEventsOnChildComponents()
{

View File

@ -22,7 +22,11 @@ namespace Microsoft.AspNetCore.Blazor.Razor
b =>
{
BlazorExtensionInitializer.Register(b);
b.Features.Remove(b.Features.OfType<HtmlBlockPass>().Single());
if (b.Features.OfType<HtmlBlockPass>().Any())
{
b.Features.Remove(b.Features.OfType<HtmlBlockPass>().Single());
}
}).Engine;
Pass.Engine = Engine;
@ -32,7 +36,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
private HtmlBlockPass Pass { get; }
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_RewritesHtml_Basic()
{
// Arrange
@ -60,7 +64,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Assert.Equal(expected, block.Content, ignoreLineEndingDifferences: true);
}
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_RewritesHtml_CSharpInAttributes()
{
// Arrange
@ -83,7 +87,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Assert.Equal(expected, block.Content, ignoreLineEndingDifferences: true);
}
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_RewritesHtml_CSharpInBody()
{
// Arrange
@ -108,7 +112,31 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Assert.Equal(expected, block.Content, ignoreLineEndingDifferences: true);
}
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_RewritesHtml_EncodesHtmlEntities()
{
// Arrange
var document = CreateDocument(@"
<div>
&lt;span&gt;Hi&lt;/span&gt;
</div>");
var expected = NormalizeContent(@"
<div>
&lt;span&gt;Hi&lt;/span&gt;
</div>");
var documentNode = Lower(document);
// Act
Pass.Execute(document, documentNode);
// Assert
var block = documentNode.FindDescendantNodes<HtmlBlockIntermediateNode>().Single();
Assert.Equal(expected, block.Content, ignoreLineEndingDifferences: true);
}
[Fact]
public void Execute_RewritesHtml_EmptyNonvoid()
{
// Arrange
@ -126,7 +154,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Assert.Equal(expected, block.Content, ignoreLineEndingDifferences: true);
}
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_RewritesHtml_Void()
{
// Arrange
@ -144,7 +172,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Assert.Equal(expected, block.Content, ignoreLineEndingDifferences: true);
}
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_CannotRewriteHtml_CSharpInCode()
{
// Arrange
@ -167,7 +195,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Assert.Empty(documentNode.FindDescendantNodes<HtmlBlockIntermediateNode>());
}
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_CannotRewriteHtml_Script()
{
// Arrange
@ -191,7 +219,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
}
// The unclosed tag will have errors, so we won't rewrite it or its parent.
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_CannotRewriteHtml_Errors()
{
// Arrange
@ -209,7 +237,7 @@ namespace Microsoft.AspNetCore.Blazor.Razor
Assert.Empty(documentNode.FindDescendantNodes<HtmlBlockIntermediateNode>());
}
[Fact(Skip = "Temporarily disable compiling markup frames in 0.5.1")]
[Fact]
public void Execute_RewritesHtml_MismatchedClosingTag()
{
// Arrange

View File

@ -0,0 +1 @@
<PassThroughContentComponent><div id="foo"><p>Some-Static-Text</p></div></PassThroughContentComponent>

View File

@ -0,0 +1,7 @@
<div>
<PassThroughContentComponent>
<div id="one"><p>Some-Static-Text</p></div>
<div id="two">&lt;span&gt;More-Static-Text&lt;/span&gt;</div>
<div><span id="three">@("Some-Dynamic-Text")</span><span id="four">But this is static</span></div>
</PassThroughContentComponent>
</div>

View File

@ -0,0 +1,7 @@
<div>
<PassThroughContentComponent>
<div id="one"><p>Some-Static-Text</p></div>
<div id="two"><span>More-Static-Text</span></div>
<div><span id="three">@("Some-Dynamic-Text")</span><span id="four">But this is static</span></div>
</PassThroughContentComponent>
</div>

View File

@ -36,6 +36,9 @@
<option value="BasicTestApp.EventBubblingComponent">Event bubbling</option>
<option value="BasicTestApp.EventPreventDefaultComponent">Event preventDefault</option>
<option value="BasicTestApp.RouterTest.TestRouter">Router</option>
<option value="BasicTestApp.HtmlBlockChildContent">ChildContent HTML Block</option>
<option value="BasicTestApp.HtmlMixedChildContent">ChildContent Mixed Block</option>
<option value="BasicTestApp.HtmlEncodedChildContent">ChildContent HTML Encoded Block</option>
</select>
@if (SelectedComponentType != null)