diff --git a/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs b/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs index 2bba2e0cb0..10fccb755e 100644 --- a/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs +++ b/src/Microsoft.AspNet.Mvc.Razor/TagHelpers/UrlResolutionTagHelper.cs @@ -176,7 +176,7 @@ namespace Microsoft.AspNet.Mvc.Razor.TagHelpers var htmlContent = attribute.Value as IHtmlContent; if (htmlContent != null) { - var htmlString = htmlContent as HtmlString; + var htmlString = htmlContent as HtmlEncodedString; if (htmlString != null) { // No need for a StringWriter in this case. diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperContentExtensions.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperContentExtensions.cs index b24da3fe48..3b5a59e4f9 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperContentExtensions.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/TagHelperContentExtensions.cs @@ -4,6 +4,7 @@ using System; using System.IO; using System.Text.Encodings.Web; +using Microsoft.AspNet.Html; using Microsoft.AspNet.Mvc.Razor; using Microsoft.AspNet.Mvc.Rendering; using Microsoft.AspNet.Razor.TagHelpers; @@ -48,7 +49,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers } string stringValue; - var htmlString = value as HtmlString; + var htmlString = value as HtmlEncodedString; if (htmlString != null) { // No need for a StringWriter in this case. diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs index bd576af98a..d396d43a1f 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Rendering/HtmlString.cs @@ -1,59 +1,25 @@ // 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.IO; -using System.Text.Encodings.Web; using Microsoft.AspNet.Html; namespace Microsoft.AspNet.Mvc.Rendering { - /// - /// String content which knows how to write itself. - /// - public class HtmlString : IHtmlContent + /// + public class HtmlString : HtmlEncodedString { - private readonly string _input; - /// /// Returns an with empty content. /// public static readonly HtmlString Empty = new HtmlString(string.Empty); - /// - /// Returns an containing . - /// - public static readonly HtmlString NewLine = new HtmlString(Environment.NewLine); - /// /// Creates a new instance of . /// - /// string to initialize . + /// The HTML encoded value. public HtmlString(string input) + : base(input) { - _input = input; - } - - /// - public void WriteTo(TextWriter writer, HtmlEncoder encoder) - { - if (writer == null) - { - throw new ArgumentNullException(nameof(writer)); - } - - if (encoder == null) - { - throw new ArgumentNullException(nameof(encoder)); - } - - writer.Write(_input); - } - - /// - public override string ToString() - { - return _input; } } } diff --git a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperTest.cs b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperTest.cs index b388ce93d9..c97b8f515a 100644 --- a/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperTest.cs +++ b/test/Microsoft.AspNet.Mvc.ViewFeatures.Test/Rendering/HtmlHelperTest.cs @@ -125,7 +125,7 @@ namespace Microsoft.AspNet.Mvc.Rendering { return new TheoryData { - { null, null }, + { null, string.Empty }, { string.Empty, string.Empty }, { "<\">", "<\">" }, { "
", "
" },