React to `HtmlEncodedString` rename to `HtmlString`.

- Removed the Mvc instance of `HtmlString` since it now exists in `HtmlAbstractions`.

#4558
aspnet/HtmlAbstractions#25
This commit is contained in:
N. Taylor Mullen 2016-05-16 16:20:30 -07:00
parent 230776f4b0
commit 55922d68d4
24 changed files with 61 additions and 54 deletions

View File

@ -184,7 +184,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.TagHelpers
var htmlContent = attribute.Value as IHtmlContent;
if (htmlContent != null)
{
var htmlString = htmlContent as HtmlEncodedString;
var htmlString = htmlContent as HtmlString;
if (htmlString != null)
{
// No need for a StringWriter in this case.

View File

@ -4,7 +4,7 @@
using System;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Html;
namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
{
@ -14,18 +14,20 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
/// </summary>
public class DistributedCacheTagHelperFormatter : IDistributedCacheTagHelperFormatter
{
/// <inheritdoc />
public Task<byte[]> SerializeAsync(DistributedCacheTagHelperFormattingContext context)
{
if (context == null)
if (context == null)
{
throw new ArgumentNullException(nameof(context));
throw new ArgumentNullException(nameof(context));
}
if (context.Html == null)
if (context.Html == null)
{
throw new ArgumentNullException(nameof(context.Html));
throw new ArgumentException(
Resources.FormatPropertyOfTypeCannotBeNull(
nameof(DistributedCacheTagHelperFormattingContext.Html),
typeof(DistributedCacheTagHelperFormattingContext).FullName));
}
var serialized = Encoding.UTF8.GetBytes(context.Html.ToString());
@ -35,11 +37,11 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
/// <inheritdoc />
public Task<HtmlString> DeserializeAsync(byte[] value)
{
if (value == null)
if (value == null)
{
throw new ArgumentNullException(nameof(value));
throw new ArgumentNullException(nameof(value));
}
var content = Encoding.UTF8.GetString(value);
return Task.FromResult(new HtmlString(content));
}

View File

@ -1,7 +1,7 @@
// 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 Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Html;
namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
{
@ -13,6 +13,6 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
/// <summary>
/// Gets the <see cref="HtmlString"/> instance.
/// </summary>
public HtmlString Html { get; set; }
public HtmlString Html { get; set; }
}
}

View File

@ -2,15 +2,15 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Html;
namespace Microsoft.AspNetCore.Mvc.TagHelpers.Cache
{
/// <summary>
/// An implementation of this interface provides a service to
/// An implementation of this interface provides a service to
/// serialize html fragments for being store by <see cref="IDistributedCacheTagHelperStorage" />
/// </summary>
public interface IDistributedCacheTagHelperFormatter
public interface IDistributedCacheTagHelperFormatter
{
/// <summary>
/// Serializes some html content.

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.Razor.TagHelpers;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.Routing;

View File

@ -154,6 +154,22 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
return string.Format(CultureInfo.CurrentCulture, GetString("FormTagHelper_CannotDetermineActionWithRouteAndActionOrControllerSpecified"), p0, p1, p2, p3, p4);
}
/// <summary>
/// The '{0}' property of '{1}' must not be null.
/// </summary>
internal static string PropertyOfTypeCannotBeNull
{
get { return GetString("PropertyOfTypeCannotBeNull"); }
}
/// <summary>
/// The '{0}' property of '{1}' must not be null.
/// </summary>
internal static string FormatPropertyOfTypeCannotBeNull(object p0, object p1)
{
return string.Format(CultureInfo.CurrentCulture, GetString("PropertyOfTypeCannotBeNull"), p0, p1);
}
private static string GetString(string name, params string[] formatterNames)
{
var value = _resourceManager.GetString(name);

View File

@ -144,4 +144,7 @@
<data name="FormTagHelper_CannotDetermineActionWithRouteAndActionOrControllerSpecified" xml:space="preserve">
<value>Cannot determine an '{4}' attribute for {0}. A {0} with a specified '{1}' must not have an '{2}' or '{3}' attribute.</value>
</data>
<data name="PropertyOfTypeCannotBeNull" xml:space="preserve">
<value>The '{0}' property of '{1}' must not be null.</value>
</data>
</root>

View File

@ -344,12 +344,12 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
private string GetAttributeValue(object value)
{
string stringValue;
var htmlEncodedString = value as HtmlEncodedString;
if (htmlEncodedString != null)
var htmlString = value as HtmlString;
if (htmlString != null)
{
// Value likely came from an HTML context in the .cshtml file but may still contain double quotes
// since attribute could have been enclosed in single quotes.
stringValue = htmlEncodedString.Value;
stringValue = htmlString.Value;
stringValue = stringValue.Replace("\"", "&quot;");
}
else
@ -358,7 +358,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
RazorPage.WriteTo(writer, HtmlEncoder, value);
// Value is now correctly HTML-encoded but may still contain double quotes since attribute could
// have been enclosed in single quotes and portions that were HtmlEncodedStrings are not re-encoded.
// have been enclosed in single quotes and portions that were HtmlStrings are not re-encoded.
var builder = writer.GetStringBuilder();
builder.Replace("\"", "&quot;");

View File

@ -49,7 +49,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
}
string stringValue;
var htmlString = value as HtmlEncodedString;
var htmlString = value as HtmlString;
if (htmlString != null)
{
// No need for a StringWriter in this case.

View File

@ -1,25 +0,0 @@
// 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 Microsoft.AspNetCore.Html;
namespace Microsoft.AspNetCore.Mvc.Rendering
{
/// <inheritdoc />
public class HtmlString : HtmlEncodedString
{
/// <summary>
/// Returns an <see cref="HtmlString"/> with empty content.
/// </summary>
public static readonly HtmlString Empty = new HtmlString(string.Empty);
/// <summary>
/// Creates a new instance of <see cref="HtmlString"/>.
/// </summary>
/// <param name="input">The HTML encoded value.</param>
public HtmlString(string input)
: base(input)
{
}
}
}

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Reflection;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
@ -223,7 +224,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
await formTagHelper.ProcessAsync(context, output);
Assert.Equal("form", output.TagName);
Assert.Equal(TagMode.StartTagAndEndTag ,output.TagMode);
Assert.Equal(TagMode.StartTagAndEndTag, output.TagMode);
var attribute = Assert.Single(output.Attributes);
Assert.Equal(expectedAttribute, attribute);
Assert.Empty(output.PreContent.GetContent());

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;
@ -142,7 +143,7 @@ namespace Microsoft.AspNetCore.Mvc.TagHelpers
Assert.Equal(expectedOutput.TagName, output.TagName);
Assert.Equal(4, output.Attributes.Count);
for(int i=0; i < expectedOutput.Attributes.Count; i++)
for (var i = 0; i < expectedOutput.Attributes.Count; i++)
{
var expectedAtribute = expectedOutput.Attributes[i];
var actualAttribute = output.Attributes[i];

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;

View File

@ -8,6 +8,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;

View File

@ -212,8 +212,8 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
// Assert
Assert.Same(nested, buffer.Pages[0].Buffer[0].Value);
Assert.Equal("Hello", Assert.IsType<HtmlEncodedString>(nestedItems[0]).Value);
Assert.Equal("Hello", Assert.IsType<HtmlEncodedString>(destinationItems[0]).Value);
Assert.Equal("Hello", Assert.IsType<HtmlString>(nestedItems[0]).Value);
Assert.Equal("Hello", Assert.IsType<HtmlString>(destinationItems[0]).Value);
}
[Fact]
@ -236,7 +236,7 @@ namespace Microsoft.AspNetCore.Mvc.ViewFeatures.Internal
// Assert
Assert.Empty(nestedItems);
Assert.Empty(buffer.Pages);
Assert.Equal("Hello", Assert.IsType<HtmlEncodedString>(destinationItems[0]).Value);
Assert.Equal("Hello", Assert.IsType<HtmlString>(destinationItems[0]).Value);
}
[Fact]

View File

@ -7,7 +7,7 @@ using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Testing;
using Microsoft.Extensions.WebEncoders.Testing;
using Moq;

View File

@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Moq;
using Xunit;

View File

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Routing;
using Microsoft.AspNetCore.Mvc.ViewFeatures;

View File

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.TestCommon;
using Xunit;

View File

@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.IO;
using Microsoft.AspNetCore.Html;
using Microsoft.Extensions.WebEncoders.Testing;
using Xunit;

View File

@ -9,11 +9,11 @@ using System.Reflection;
using System.Text;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.Internal;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.TestCommon;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.Mvc.ViewFeatures;

View File

@ -2,7 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Xunit;

View File

@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Abstractions;
using Microsoft.AspNetCore.Mvc.ModelBinding;