From 3ba92523ff90c9d77fc8c1dd5e722927e10e21c1 Mon Sep 17 00:00:00 2001 From: "N. Taylor Mullen" Date: Fri, 29 May 2015 15:06:14 -0700 Subject: [PATCH] Remove special casing of '*' in TagHelperDescriptorProvider. - Requesting a '*' tagName from the TagHelperDescriptorProvider could only happen if a user was directly calling into it (extremely unlikely). Therefore I've removed the special casing to make the logic more simple. - Removed tests that expected this behavior. #324 --- .../TagHelpers/TagHelperDescriptorProvider.cs | 15 +++---- .../TagHelperDescriptorProviderTest.cs | 45 ------------------- 2 files changed, 5 insertions(+), 55 deletions(-) diff --git a/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperDescriptorProvider.cs b/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperDescriptorProvider.cs index 38ce94c95f..b4185f8edd 100644 --- a/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperDescriptorProvider.cs +++ b/src/Microsoft.AspNet.Razor/TagHelpers/TagHelperDescriptorProvider.cs @@ -66,17 +66,12 @@ namespace Microsoft.AspNet.Razor.TagHelpers descriptors = catchAllDescriptors; } - // If the requested tag name is the catch-all target, we shouldn't do the work of concatenating extra - // descriptors. - if (!tagName.Equals(ElementCatchAllTarget, StringComparison.OrdinalIgnoreCase)) + // If we have a tag name associated with the requested name, we need to combine matchingDescriptors + // with all the catch-all descriptors. + HashSet matchingDescriptors; + if (_registrations.TryGetValue(tagName, out matchingDescriptors)) { - // If we have a tag name associated with the requested name, we need to combine matchingDescriptors - // with all the catch-all descriptors. - HashSet matchingDescriptors; - if (_registrations.TryGetValue(tagName, out matchingDescriptors)) - { - descriptors = matchingDescriptors.Concat(descriptors); - } + descriptors = matchingDescriptors.Concat(descriptors); } var applicableDescriptors = ApplyRequiredAttributes(descriptors, attributeNames); diff --git a/test/Microsoft.AspNet.Razor.Test/TagHelpers/TagHelperDescriptorProviderTest.cs b/test/Microsoft.AspNet.Razor.Test/TagHelpers/TagHelperDescriptorProviderTest.cs index 599c71e5cb..14f9a98fd9 100644 --- a/test/Microsoft.AspNet.Razor.Test/TagHelpers/TagHelperDescriptorProviderTest.cs +++ b/test/Microsoft.AspNet.Razor.Test/TagHelpers/TagHelperDescriptorProviderTest.cs @@ -86,30 +86,6 @@ namespace Microsoft.AspNet.Razor.TagHelpers defaultAvailableDescriptors, new[] { inputDescriptor, catchAllDescriptor } }, - { - TagHelperDescriptorProvider.ElementCatchAllTarget, - new[] { "custom" }, - defaultAvailableDescriptors, - Enumerable.Empty() - }, - { - TagHelperDescriptorProvider.ElementCatchAllTarget, - new[] { "class" }, - defaultAvailableDescriptors, - new[] { catchAllDescriptor } - }, - { - TagHelperDescriptorProvider.ElementCatchAllTarget, - new[] { "class", "style" }, - defaultAvailableDescriptors, - new[] { catchAllDescriptor } - }, - { - TagHelperDescriptorProvider.ElementCatchAllTarget, - new[] { "class", "custom" }, - defaultAvailableDescriptors, - new[] { catchAllDescriptor, catchAllDescriptor2 } - }, { "input", new[] { "nodashprefixA" }, @@ -291,27 +267,6 @@ namespace Microsoft.AspNet.Razor.TagHelpers Assert.Empty(retrievedDescriptors); } - [Fact] - public void GetDescriptors_DoesNotReturnNonCatchAllTagsForCatchAll() - { - // Arrange - var divDescriptor = new TagHelperDescriptor("div", "foo1", "SomeAssembly"); - var spanDescriptor = new TagHelperDescriptor("span", "foo2", "SomeAssembly"); - var catchAllDescriptor = new TagHelperDescriptor( - TagHelperDescriptorProvider.ElementCatchAllTarget, - "foo3", - "SomeAssembly"); - var descriptors = new TagHelperDescriptor[] { divDescriptor, spanDescriptor, catchAllDescriptor }; - var provider = new TagHelperDescriptorProvider(descriptors); - - // Act - var retrievedDescriptors = provider.GetDescriptors(TagHelperDescriptorProvider.ElementCatchAllTarget, attributeNames: Enumerable.Empty()); - - // Assert - var descriptor = Assert.Single(retrievedDescriptors); - Assert.Same(catchAllDescriptor, descriptor); - } - [Fact] public void GetDescriptors_ReturnsCatchAllsWithEveryTagName() {