Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 8a7a19f

Browse files
author
N. Taylor Mullen
committed
Addressed pranav's code review comments.
1 parent d3af121 commit 8a7a19f

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperOutputExtensions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,12 @@ public static void CopyHtmlAttribute(this TagHelperOutput tagHelperOutput,
3030
TagHelperContext context)
3131
{
3232
// We look for the original attribute so we can restore the exact attribute name the user typed.
33-
var entry = context.AllAttributes.Single(attribute =>
33+
var entry = context.AllAttributes.First(attribute =>
3434
attribute.Key.Equals(attributeName, StringComparison.OrdinalIgnoreCase));
35-
var originalAttribute = new KeyValuePair<string, string>(entry.Key, entry.Value.ToString());
3635

37-
if (!tagHelperOutput.Attributes.ContainsKey(originalAttribute.Key))
36+
if (!tagHelperOutput.Attributes.ContainsKey(entry.Key))
3837
{
39-
tagHelperOutput.Attributes.Add(originalAttribute);
38+
tagHelperOutput.Attributes.Add(entry.Key, entry.Value.ToString());
4039
}
4140
}
4241

test/Microsoft.AspNet.Mvc.TagHelpers.Test/TagHelperOutputExtensionsTest.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Linq;
67
using Microsoft.AspNet.Mvc.Rendering;
@@ -22,7 +23,7 @@ public void CopyHtmlAttribute_CopiesOriginalAttributes(string attributeName, str
2223
attributes: new Dictionary<string, string>(),
2324
content: string.Empty);
2425
var tagHelperContext = new TagHelperContext(
25-
new Dictionary<string, object>()
26+
new Dictionary<string, object>(StringComparer.Ordinal)
2627
{
2728
{ attributeName, attributeValue }
2829
});
@@ -43,14 +44,14 @@ public void CopyHtmlAttribute_DoesntOverrideAttributes()
4344
var attributeName = "hello";
4445
var tagHelperOutput = new TagHelperOutput(
4546
"p",
46-
attributes: new Dictionary<string, string>
47+
attributes: new Dictionary<string, string>()
4748
{
4849
{ attributeName, "world2" }
4950
},
5051
content: string.Empty);
5152
var expectedAttribute = new KeyValuePair<string, string>(attributeName, "world2");
5253
var tagHelperContext = new TagHelperContext(
53-
new Dictionary<string, object>()
54+
new Dictionary<string, object>(StringComparer.Ordinal)
5455
{
5556
{ attributeName, "world" }
5657
});

0 commit comments

Comments
 (0)