Ignoring razor comments during validation
This commit is contained in:
parent
47228dd822
commit
679acdc5d4
|
|
@ -116,7 +116,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
continue;
|
||||
}
|
||||
}
|
||||
else if (!IsCommentTag((Span)child))
|
||||
else if (!IsComment((Span)child))
|
||||
{
|
||||
ValidateParentAllowsContent((Span)child, errorSink);
|
||||
}
|
||||
|
|
@ -817,9 +817,12 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
return relevantSymbol.Type == HtmlSymbolType.ForwardSlash;
|
||||
}
|
||||
|
||||
private static bool IsCommentTag(Span span)
|
||||
private static bool IsComment(Span span)
|
||||
{
|
||||
return span.Content.StartsWith("<!--");
|
||||
bool isHtmlComment = span.Content?.StartsWith("<!--") == true;
|
||||
bool isRazorComment = span.Parent?.Type == BlockKindInternal.Comment;
|
||||
|
||||
return isHtmlComment || isRazorComment;
|
||||
}
|
||||
|
||||
private static void EnsureTagBlock(Block tagBlock)
|
||||
|
|
|
|||
|
|
@ -1109,7 +1109,7 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void Rewrite_AllowsCommentsAsChildren()
|
||||
public void Rewrite_AllowsHtmlCommentsAsChildren()
|
||||
{
|
||||
// Arrangestring documentContent,
|
||||
IEnumerable<string> allowedChildren = new List<string> { "b" };
|
||||
|
|
@ -1148,6 +1148,51 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
|||
Array.Empty<RazorDiagnostic>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Rewrite_AllowsRazorCommentsAsChildren()
|
||||
{
|
||||
// Arrangestring documentContent,
|
||||
IEnumerable<string> allowedChildren = new List<string> { "b" };
|
||||
string literal = "asdf";
|
||||
string commentOutput = $"@*{literal}*@";
|
||||
string expectedOutput = $"<p><b>{literal}</b>{commentOutput}</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",
|
||||
blockFactory.MarkupTagBlock("<b>"),
|
||||
factory.Markup(literal),
|
||||
blockFactory.MarkupTagBlock("</b>"),
|
||||
new CommentBlock(
|
||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.Span(SpanKindInternal.Comment, new HtmlSymbol(literal, HtmlSymbolType.RazorComment)).Accepts(AcceptedCharactersInternal.Any),
|
||||
Factory.MetaMarkup("*", HtmlSymbolType.RazorCommentStar).Accepts(AcceptedCharactersInternal.None),
|
||||
Factory.MarkupTransition(HtmlSymbolType.RazorCommentTransition).Accepts(AcceptedCharactersInternal.None))));
|
||||
|
||||
// Act & Assert
|
||||
EvaluateData(
|
||||
descriptors,
|
||||
expectedOutput,
|
||||
expectedMarkup,
|
||||
Array.Empty<RazorDiagnostic>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Rewrite_UnderstandsNullTagNameWithAllowedChildrenForCatchAll()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue