forked from aspnet/Mvc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve
class
casing when merging a TagBuilder
into a `TagHelper…
…Output` - aspnet#5313 Also: - preserve existing `TagHelperAttribute.ValueStyle` - fix this in `UrlResolutionTagHelper`, `LinkTagHelper`, and `ScriptTagHelper` as well - correct handling of non-`string` `classAttribute.Value`s in `TagHelperOutputExtensions` - relates to aspnet#3918 because new `ClassAttributeHtmlContent` is smaller than any concatenated attribute value nit: clean up `CacheTagHelper` whitespace and `using`s
- Loading branch information
Showing
10 changed files
with
191 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
test/Microsoft.AspNetCore.Mvc.TagHelpers.Test/CaseSensitiveTagHelperAttributeComparer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Microsoft.AspNetCore.Html; | ||
using Microsoft.AspNetCore.Razor.TagHelpers; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.TagHelpers | ||
{ | ||
public class CaseSensitiveTagHelperAttributeComparer : IEqualityComparer<TagHelperAttribute> | ||
{ | ||
public readonly static CaseSensitiveTagHelperAttributeComparer Default = | ||
new CaseSensitiveTagHelperAttributeComparer(); | ||
|
||
private CaseSensitiveTagHelperAttributeComparer() | ||
{ | ||
} | ||
|
||
public bool Equals(TagHelperAttribute attributeX, TagHelperAttribute attributeY) | ||
{ | ||
if (attributeX == attributeY) | ||
{ | ||
return true; | ||
} | ||
|
||
// Normal comparer (TagHelperAttribute.Equals()) doesn't care about the Name case, in tests we do. | ||
return attributeX != null && | ||
string.Equals(attributeX.Name, attributeY.Name, StringComparison.Ordinal) && | ||
attributeX.ValueStyle == attributeY.ValueStyle && | ||
(attributeX.ValueStyle == HtmlAttributeValueStyle.Minimized || | ||
string.Equals(GetString(attributeX.Value), GetString(attributeY.Value))); | ||
} | ||
|
||
public int GetHashCode(TagHelperAttribute attribute) | ||
{ | ||
// Manually combine hash codes here. We can't reference HashCodeCombiner because we have internals visible | ||
// from Mvc.Core and Mvc.TagHelpers; both of which reference HashCodeCombiner. | ||
var baseHashCode = 0x1505L; | ||
var attributeHashCode = attribute.GetHashCode(); | ||
var combinedHash = ((baseHashCode << 5) + baseHashCode) ^ attributeHashCode; | ||
var nameHashCode = StringComparer.Ordinal.GetHashCode(attribute.Name); | ||
combinedHash = ((combinedHash << 5) + combinedHash) ^ nameHashCode; | ||
|
||
return combinedHash.GetHashCode(); | ||
} | ||
|
||
private string GetString(object value) | ||
{ | ||
var htmlContent = value as IHtmlContent; | ||
if (htmlContent != null) | ||
{ | ||
using (var writer = new StringWriter()) | ||
{ | ||
htmlContent.WriteTo(writer, NullHtmlEncoder.Default); | ||
return writer.ToString(); | ||
} | ||
} | ||
|
||
return value?.ToString() ?? string.Empty; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.