diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperOutputExtensions.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperOutputExtensions.cs index 4a5ee01b51..53edc982a5 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperOutputExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperOutputExtensions.cs @@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers [NotNull] this TagHelperOutput tagHelperOutput, [NotNull] IEnumerable attributes) { - foreach (var attribute in attributes) + foreach (var attribute in attributes.ToArray()) { tagHelperOutput.Attributes.Remove(attribute); } diff --git a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs index 61ec08166d..4ca8d60917 100644 --- a/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs +++ b/test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor.Runtime.TagHelpers; @@ -209,7 +210,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers } [Fact] - public void RemoveRange_RemovesProvidedAttributes() + public void RemoveRange_RemovesProvidedAttributes_WithArrayInput() { // Arrange var tagHelperOutput = new TagHelperOutput( @@ -231,6 +232,30 @@ namespace Microsoft.AspNet.Mvc.TagHelpers Assert.Equal(expectedAttribute, attribute); } + [Fact] + public void RemoveRange_RemovesProvidedAttributes_WithCollectionInput() + { + // Arrange + var tagHelperOutput = new TagHelperOutput( + "p", + attributes: new TagHelperAttributeList() + { + { "route-Hello", "World" }, + { "Route-I", "Am" } + }); + var expectedAttribute = new TagHelperAttribute("type", "btn"); + tagHelperOutput.Attributes.Add(expectedAttribute); + var attributes = tagHelperOutput.Attributes + .Where(item => item.Name.StartsWith("route-", StringComparison.OrdinalIgnoreCase)); + + // Act + tagHelperOutput.RemoveRange(attributes); + + // Assert + var attribute = Assert.Single(tagHelperOutput.Attributes); + Assert.Equal(expectedAttribute, attribute); + } + [Fact] public void FindPrefixedAttributes_ReturnsEmpty_AttributeListIfNoAttributesPrefixed() {