From 0c8dddcc40e1f0d9856ca380afd263a2d7f0308f Mon Sep 17 00:00:00 2001 From: Artak Mkrtchyan Date: Thu, 22 Feb 2018 17:05:13 -0800 Subject: [PATCH] Added the AllowHtmlCommentsInTagHelpers feature flag to control behavior of having comments in TagHelpers --- .../Legacy/TagHelperParseTreeRewriter.cs | 8 +++++++- .../RazorParserFeatureFlags.cs | 11 +++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperParseTreeRewriter.cs b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperParseTreeRewriter.cs index 6cac8b46ea..a4c9906b1a 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperParseTreeRewriter.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/Legacy/TagHelperParseTreeRewriter.cs @@ -488,7 +488,13 @@ namespace Microsoft.AspNetCore.Razor.Language.Legacy 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; if (!string.IsNullOrWhiteSpace(content)) diff --git a/src/Microsoft.AspNetCore.Razor.Language/RazorParserFeatureFlags.cs b/src/Microsoft.AspNetCore.Razor.Language/RazorParserFeatureFlags.cs index 0629eb9af8..409718b640 100644 --- a/src/Microsoft.AspNetCore.Razor.Language/RazorParserFeatureFlags.cs +++ b/src/Microsoft.AspNetCore.Razor.Language/RazorParserFeatureFlags.cs @@ -8,26 +8,33 @@ namespace Microsoft.AspNetCore.Razor.Language public static RazorParserFeatureFlags Create(RazorLanguageVersion version) { var allowMinimizedBooleanTagHelperAttributes = false; + var allowHtmlCommentsInTagHelpers = false; if (version.CompareTo(RazorLanguageVersion.Version_2_1) >= 0) { // Added in 2.1 allowMinimizedBooleanTagHelperAttributes = true; + allowHtmlCommentsInTagHelpers = true; } - return new DefaultRazorParserFeatureFlags(allowMinimizedBooleanTagHelperAttributes); + return new DefaultRazorParserFeatureFlags(allowMinimizedBooleanTagHelperAttributes, allowHtmlCommentsInTagHelpers); } public abstract bool AllowMinimizedBooleanTagHelperAttributes { get; } + public abstract bool AllowHtmlCommentsInTagHelpers { get; } + private class DefaultRazorParserFeatureFlags : RazorParserFeatureFlags { - public DefaultRazorParserFeatureFlags(bool allowMinimizedBooleanTagHelperAttributes) + public DefaultRazorParserFeatureFlags(bool allowMinimizedBooleanTagHelperAttributes, bool allowHtmlCommentsInTagHelpers) { AllowMinimizedBooleanTagHelperAttributes = allowMinimizedBooleanTagHelperAttributes; + AllowHtmlCommentsInTagHelpers = allowHtmlCommentsInTagHelpers; } public override bool AllowMinimizedBooleanTagHelperAttributes { get; } + + public override bool AllowHtmlCommentsInTagHelpers { get; } } } }