Enable `TagHelper`s with `[RestrictChildren]` to log errors for no tag name tags when targeted by catch all.
#534
This commit is contained in:
parent
635514453b
commit
c494cb344d
|
|
@ -325,7 +325,7 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
||||||
|
|
||||||
private void ValidateParentTagHelperAllowsTagHelper(string tagName, Block tagBlock, ErrorSink errorSink)
|
private void ValidateParentTagHelperAllowsTagHelper(string tagName, Block tagBlock, ErrorSink errorSink)
|
||||||
{
|
{
|
||||||
var currentlyAllowedChildren = _currentTagHelperTracker?.AllowedChildren;
|
var currentlyAllowedChildren = _currentTagHelperTracker?.PrefixedAllowedChildren;
|
||||||
|
|
||||||
if (currentlyAllowedChildren != null &&
|
if (currentlyAllowedChildren != null &&
|
||||||
!currentlyAllowedChildren.Contains(tagName, StringComparer.OrdinalIgnoreCase))
|
!currentlyAllowedChildren.Contains(tagName, StringComparer.OrdinalIgnoreCase))
|
||||||
|
|
@ -583,9 +583,11 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
||||||
var tagHelperPrefix = Builder.Descriptors.First().Prefix;
|
var tagHelperPrefix = Builder.Descriptors.First().Prefix;
|
||||||
|
|
||||||
AllowedChildren = Builder.Descriptors
|
AllowedChildren = Builder.Descriptors
|
||||||
|
.Where(descriptor => descriptor.AllowedChildren != null)
|
||||||
.SelectMany(descriptor => descriptor.AllowedChildren)
|
.SelectMany(descriptor => descriptor.AllowedChildren)
|
||||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
.Distinct(StringComparer.OrdinalIgnoreCase);
|
||||||
.Select(allowedChild => tagHelperPrefix + allowedChild);
|
|
||||||
|
PrefixedAllowedChildren = AllowedChildren.Select(allowedChild => tagHelperPrefix + allowedChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -594,6 +596,8 @@ namespace Microsoft.AspNet.Razor.Parser.TagHelpers.Internal
|
||||||
public uint OpenMatchingTags { get; set; }
|
public uint OpenMatchingTags { get; set; }
|
||||||
|
|
||||||
public IEnumerable<string> AllowedChildren { get; }
|
public IEnumerable<string> AllowedChildren { get; }
|
||||||
|
|
||||||
|
public IEnumerable<string> PrefixedAllowedChildren { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -747,6 +747,86 @@ namespace Microsoft.AspNet.Razor.Test.TagHelpers
|
||||||
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
|
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Rewrite_UnderstandsNullTagNameWithAllowedChildrenForCatchAll()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documentContent = "<p></</p>";
|
||||||
|
var descriptors = new TagHelperDescriptor[]
|
||||||
|
{
|
||||||
|
new TagHelperDescriptor
|
||||||
|
{
|
||||||
|
TagName = "p",
|
||||||
|
TypeName = "PTagHelper",
|
||||||
|
AssemblyName = "SomeAssembly",
|
||||||
|
AllowedChildren = new[] { "custom" },
|
||||||
|
},
|
||||||
|
new TagHelperDescriptor
|
||||||
|
{
|
||||||
|
TagName = "*",
|
||||||
|
TypeName = "CatchAllTagHelper",
|
||||||
|
AssemblyName = "SomeAssembly",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var expectedOutput = new MarkupBlock(
|
||||||
|
new MarkupTagHelperBlock("p",
|
||||||
|
BlockFactory.MarkupTagBlock("</")));
|
||||||
|
var descriptorProvider = new TagHelperDescriptorProvider(descriptors);
|
||||||
|
var expectedErrors = new[]
|
||||||
|
{
|
||||||
|
new RazorError(
|
||||||
|
RazorResources.FormatTagHelperParseTreeRewriter_CannotHaveNonTagContent("p", "custom"),
|
||||||
|
absoluteIndex: 3,
|
||||||
|
lineIndex: 0,
|
||||||
|
columnIndex: 3,
|
||||||
|
length: 2)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void Rewrite_UnderstandsNullTagNameWithAllowedChildrenForCatchAllWithPrefix()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
var documentContent = "<th:p></</th:p>";
|
||||||
|
var descriptors = new TagHelperDescriptor[]
|
||||||
|
{
|
||||||
|
new TagHelperDescriptor
|
||||||
|
{
|
||||||
|
TagName = "p",
|
||||||
|
TypeName = "PTagHelper",
|
||||||
|
AssemblyName = "SomeAssembly",
|
||||||
|
AllowedChildren = new[] { "custom" },
|
||||||
|
Prefix = "th:",
|
||||||
|
},
|
||||||
|
new TagHelperDescriptor
|
||||||
|
{
|
||||||
|
TagName = "*",
|
||||||
|
TypeName = "CatchAllTagHelper",
|
||||||
|
AssemblyName = "SomeAssembly",
|
||||||
|
Prefix = "th:",
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var expectedOutput = new MarkupBlock(
|
||||||
|
new MarkupTagHelperBlock("th:p",
|
||||||
|
BlockFactory.MarkupTagBlock("</")));
|
||||||
|
var descriptorProvider = new TagHelperDescriptorProvider(descriptors);
|
||||||
|
var expectedErrors = new[]
|
||||||
|
{
|
||||||
|
new RazorError(
|
||||||
|
RazorResources.FormatTagHelperParseTreeRewriter_CannotHaveNonTagContent("th:p", "custom"),
|
||||||
|
absoluteIndex: 6,
|
||||||
|
lineIndex: 0,
|
||||||
|
columnIndex: 6,
|
||||||
|
length: 2)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Act & Assert
|
||||||
|
EvaluateData(descriptorProvider, documentContent, expectedOutput, expectedErrors);
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void Rewrite_CanHandleStartTagOnlyTagTagMode()
|
public void Rewrite_CanHandleStartTagOnlyTagTagMode()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue