Added a unit test to repro the issue

This commit is contained in:
Artak Mkrtchyan 2018-02-08 15:50:38 -08:00
parent 69c2d08326
commit e6f68eb244
No known key found for this signature in database
GPG Key ID: 64D580ACBA8CA645
2 changed files with 44 additions and 7 deletions

View File

@ -488,7 +488,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
private void ValidateParentAllowsContent(Span child, ErrorSink errorSink) private void ValidateParentAllowsContent(Span child, ErrorSink errorSink)
{ {
if (HasAllowedChildren()) if (child.Kind == SpanKindInternal.Comment || HasAllowedChildren())
{ {
var content = child.Content; var content = child.Content;
if (!string.IsNullOrWhiteSpace(content)) if (!string.IsNullOrWhiteSpace(content))

View File

@ -1108,6 +1108,43 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors); EvaluateData(descriptors, documentContent, (MarkupBlock)expectedOutput, (RazorDiagnostic[])expectedErrors);
} }
[Fact]
public void Rewrite_AllowsCommentsAsChildren()
{
// Arrangestring documentContent,
IEnumerable<string> allowedChildren = new List<string> { "b" };
string literalPrefix = "";
string commentOutput = $"<!--Hello World-->";
string expectedOutput = $"<p>{literalPrefix}{commentOutput}<b>asdf</b></p>";
var pTagHelperBuilder = TagHelperDescriptorBuilder
.Create("PTagHelper", "SomeAssembly")
.TagMatchingRuleDescriptor(rule => rule.RequireTagName("p"));
foreach (var childTag in allowedChildren)
{
pTagHelperBuilder.AllowChildTag(childTag);
}
var descriptors = new TagHelperDescriptor[]
{
pTagHelperBuilder.Build()
};
var factory = new SpanFactory();
var blockFactory = new BlockFactory(factory);
var expectedMarkup = new MarkupBlock(
new MarkupTagHelperBlock("p",
factory.Markup($"{literalPrefix}{commentOutput}")));
// Act & Assert
EvaluateData(
descriptors,
expectedOutput,
expectedMarkup,
Array.Empty<RazorDiagnostic>());
}
[Fact] [Fact]
public void Rewrite_UnderstandsNullTagNameWithAllowedChildrenForCatchAll() public void Rewrite_UnderstandsNullTagNameWithAllowedChildrenForCatchAll()
{ {