Added the AllowHtmlCommentsInTagHelpers feature flag to control behavior of having comments in TagHelpers
This commit is contained in:
parent
2949470a43
commit
0c8dddcc40
|
|
@ -488,7 +488,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy
|
||||||
|
|
||||||
private void ValidateParentAllowsContent(Span child, ErrorSink errorSink)
|
private void ValidateParentAllowsContent(Span child, ErrorSink errorSink)
|
||||||
{
|
{
|
||||||
if (HasAllowedChildren() && !IsComment(child) && child.Kind != SpanKindInternal.Transition && child.Kind != SpanKindInternal.Code)
|
var isDisallowedContent = true;
|
||||||
|
if (_featureFlags.AllowHtmlCommentsInTagHelpers)
|
||||||
|
{
|
||||||
|
isDisallowedContent = !IsComment(child) && child.Kind != SpanKindInternal.Transition && child.Kind != SpanKindInternal.Code;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (HasAllowedChildren() && isDisallowedContent)
|
||||||
{
|
{
|
||||||
var content = child.Content;
|
var content = child.Content;
|
||||||
if (!string.IsNullOrWhiteSpace(content))
|
if (!string.IsNullOrWhiteSpace(content))
|
||||||
|
|
|
||||||
|
|
@ -8,26 +8,33 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
public static RazorParserFeatureFlags Create(RazorLanguageVersion version)
|
public static RazorParserFeatureFlags Create(RazorLanguageVersion version)
|
||||||
{
|
{
|
||||||
var allowMinimizedBooleanTagHelperAttributes = false;
|
var allowMinimizedBooleanTagHelperAttributes = false;
|
||||||
|
var allowHtmlCommentsInTagHelpers = false;
|
||||||
|
|
||||||
if (version.CompareTo(RazorLanguageVersion.Version_2_1) >= 0)
|
if (version.CompareTo(RazorLanguageVersion.Version_2_1) >= 0)
|
||||||
{
|
{
|
||||||
// Added in 2.1
|
// Added in 2.1
|
||||||
allowMinimizedBooleanTagHelperAttributes = true;
|
allowMinimizedBooleanTagHelperAttributes = true;
|
||||||
|
allowHtmlCommentsInTagHelpers = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DefaultRazorParserFeatureFlags(allowMinimizedBooleanTagHelperAttributes);
|
return new DefaultRazorParserFeatureFlags(allowMinimizedBooleanTagHelperAttributes, allowHtmlCommentsInTagHelpers);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract bool AllowMinimizedBooleanTagHelperAttributes { get; }
|
public abstract bool AllowMinimizedBooleanTagHelperAttributes { get; }
|
||||||
|
|
||||||
|
public abstract bool AllowHtmlCommentsInTagHelpers { get; }
|
||||||
|
|
||||||
private class DefaultRazorParserFeatureFlags : RazorParserFeatureFlags
|
private class DefaultRazorParserFeatureFlags : RazorParserFeatureFlags
|
||||||
{
|
{
|
||||||
public DefaultRazorParserFeatureFlags(bool allowMinimizedBooleanTagHelperAttributes)
|
public DefaultRazorParserFeatureFlags(bool allowMinimizedBooleanTagHelperAttributes, bool allowHtmlCommentsInTagHelpers)
|
||||||
{
|
{
|
||||||
AllowMinimizedBooleanTagHelperAttributes = allowMinimizedBooleanTagHelperAttributes;
|
AllowMinimizedBooleanTagHelperAttributes = allowMinimizedBooleanTagHelperAttributes;
|
||||||
|
AllowHtmlCommentsInTagHelpers = allowHtmlCommentsInTagHelpers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool AllowMinimizedBooleanTagHelperAttributes { get; }
|
public override bool AllowMinimizedBooleanTagHelperAttributes { get; }
|
||||||
|
|
||||||
|
public override bool AllowHtmlCommentsInTagHelpers { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue