[Fixes #2491] RemoveRange handles attributes parameter safely
This commit is contained in:
parent
c0ca6214c2
commit
0a7b2ac821
|
|
@ -117,7 +117,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
[NotNull] this TagHelperOutput tagHelperOutput,
|
[NotNull] this TagHelperOutput tagHelperOutput,
|
||||||
[NotNull] IEnumerable<TagHelperAttribute> attributes)
|
[NotNull] IEnumerable<TagHelperAttribute> attributes)
|
||||||
{
|
{
|
||||||
foreach (var attribute in attributes)
|
foreach (var attribute in attributes.ToArray())
|
||||||
{
|
{
|
||||||
tagHelperOutput.Attributes.Remove(attribute);
|
tagHelperOutput.Attributes.Remove(attribute);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNet.Mvc.Rendering;
|
using Microsoft.AspNet.Mvc.Rendering;
|
||||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||||
|
|
@ -209,7 +210,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void RemoveRange_RemovesProvidedAttributes()
|
public void RemoveRange_RemovesProvidedAttributes_WithArrayInput()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var tagHelperOutput = new TagHelperOutput(
|
var tagHelperOutput = new TagHelperOutput(
|
||||||
|
|
@ -231,6 +232,30 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
||||||
Assert.Equal(expectedAttribute, attribute);
|
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]
|
[Fact]
|
||||||
public void FindPrefixedAttributes_ReturnsEmpty_AttributeListIfNoAttributesPrefixed()
|
public void FindPrefixedAttributes_ReturnsEmpty_AttributeListIfNoAttributesPrefixed()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue