React to BufferedHtmlContent changes
This commit is contained in:
parent
85bb33a62a
commit
94388a8804
|
|
@ -271,9 +271,7 @@ Global
|
|||
{4DA2D7C1-A7B6-4C01-B57D-89E6EA4609DE}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{4DA2D7C1-A7B6-4C01-B57D-89E6EA4609DE}.Release|x86.Build.0 = Release|Any CPU
|
||||
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{F504357E-C2E1-4818-BA5C-9A2EAC25FEE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
|
@ -378,6 +376,7 @@ Global
|
|||
{F21E225B-190B-4DAA-8B0A-05986D231F56}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{F21E225B-190B-4DAA-8B0A-05986D231F56}.Release|x86.Build.0 = Release|Any CPU
|
||||
{3F8B8FC1-9FE4-4788-8991-367113E8D7AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{3F8B8FC1-9FE4-4788-8991-367113E8D7AD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3F8B8FC1-9FE4-4788-8991-367113E8D7AD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
|
||||
{3F8B8FC1-9FE4-4788-8991-367113E8D7AD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
|
||||
{3F8B8FC1-9FE4-4788-8991-367113E8D7AD}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
// 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 System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Html.Abstractions;
|
||||
using Microsoft.AspNet.Mvc.Razor.Internal;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -30,9 +32,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="unbufferedWriter">The <see cref="TextWriter"/> to write output to when this instance
|
||||
/// is no longer buffering.</param>
|
||||
/// <param name="encoding">The character <see cref="Encoding"/> in which the output is written.</param>
|
||||
public RazorTextWriter(TextWriter unbufferedWriter, Encoding encoding)
|
||||
/// <param name="encoder">The HTML encoder.</param>
|
||||
public RazorTextWriter(TextWriter unbufferedWriter, Encoding encoding, IHtmlEncoder encoder)
|
||||
{
|
||||
UnbufferedWriter = unbufferedWriter;
|
||||
HtmlEncoder = encoder;
|
||||
|
||||
BufferedWriter = new StringCollectionTextWriter(encoding);
|
||||
TargetWriter = BufferedWriter;
|
||||
}
|
||||
|
|
@ -53,8 +58,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
|
||||
private TextWriter TargetWriter { get; set; }
|
||||
|
||||
[RazorInject]
|
||||
private IHtmlEncoder HtmlEncoder { get; set; }
|
||||
private IHtmlEncoder HtmlEncoder { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(char value)
|
||||
|
|
@ -65,10 +69,10 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <inheritdoc />
|
||||
public override void Write(object value)
|
||||
{
|
||||
var htmlString = value as HtmlString;
|
||||
if (htmlString != null)
|
||||
var htmlContent = value as IHtmlContent;
|
||||
if (htmlContent != null)
|
||||
{
|
||||
htmlString.WriteTo(TargetWriter, HtmlEncoder);
|
||||
htmlContent.WriteTo(TargetWriter, HtmlEncoder);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ using Microsoft.AspNet.Http.Features;
|
|||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.PageExecutionInstrumentation;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -21,6 +22,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
private readonly IRazorViewEngine _viewEngine;
|
||||
private readonly IRazorPageActivator _pageActivator;
|
||||
private readonly IViewStartProvider _viewStartProvider;
|
||||
private readonly IHtmlEncoder _htmlEncoder;
|
||||
private IPageExecutionListenerFeature _pageExecutionFeature;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -30,18 +32,21 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="pageActivator">The <see cref="IRazorPageActivator"/> used to activate pages.</param>
|
||||
/// <param name="viewStartProvider">The <see cref="IViewStartProvider"/> used for discovery of _ViewStart
|
||||
/// <param name="razorPage">The <see cref="IRazorPage"/> instance to execute.</param>
|
||||
/// <param name="htmlEncoder">The HTML encoder.</param>
|
||||
/// <param name="isPartial">Determines if the view is to be executed as a partial.</param>
|
||||
/// pages</param>
|
||||
public RazorView(IRazorViewEngine viewEngine,
|
||||
IRazorPageActivator pageActivator,
|
||||
IViewStartProvider viewStartProvider,
|
||||
IRazorPage razorPage,
|
||||
IHtmlEncoder htmlEncoder,
|
||||
bool isPartial)
|
||||
{
|
||||
_viewEngine = viewEngine;
|
||||
_pageActivator = pageActivator;
|
||||
_viewStartProvider = viewStartProvider;
|
||||
RazorPage = razorPage;
|
||||
_htmlEncoder = htmlEncoder;
|
||||
IsPartial = isPartial;
|
||||
}
|
||||
|
||||
|
|
@ -77,11 +82,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
await RenderLayoutAsync(context, bodyWriter);
|
||||
}
|
||||
|
||||
private async Task<IBufferedTextWriter> RenderPageAsync(IRazorPage page,
|
||||
ViewContext context,
|
||||
bool executeViewStart)
|
||||
private async Task<IBufferedTextWriter> RenderPageAsync(
|
||||
IRazorPage page,
|
||||
ViewContext context,
|
||||
bool executeViewStart)
|
||||
{
|
||||
var razorTextWriter = new RazorTextWriter(context.Writer, context.Writer.Encoding);
|
||||
var razorTextWriter = new RazorTextWriter(context.Writer, context.Writer.Encoding, _htmlEncoder);
|
||||
var writer = (TextWriter)razorTextWriter;
|
||||
var bufferedWriter = (IBufferedTextWriter)razorTextWriter;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
namespace Microsoft.AspNet.Mvc.Razor
|
||||
{
|
||||
|
|
@ -12,6 +13,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// </summary>
|
||||
public class RazorViewFactory : IRazorViewFactory
|
||||
{
|
||||
private readonly IHtmlEncoder _htmlEncoder;
|
||||
private readonly IRazorPageActivator _pageActivator;
|
||||
private readonly IViewStartProvider _viewStartProvider;
|
||||
|
||||
|
|
@ -22,10 +24,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <param name="viewStartProvider">The <see cref="IViewStartProvider"/> used for discovery of _ViewStart
|
||||
/// pages</param>
|
||||
public RazorViewFactory(IRazorPageActivator pageActivator,
|
||||
IViewStartProvider viewStartProvider)
|
||||
IViewStartProvider viewStartProvider,
|
||||
IHtmlEncoder htmlEncoder)
|
||||
{
|
||||
_pageActivator = pageActivator;
|
||||
_viewStartProvider = viewStartProvider;
|
||||
_htmlEncoder = htmlEncoder;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -33,7 +37,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
[NotNull] IRazorPage page,
|
||||
bool isPartial)
|
||||
{
|
||||
var razorView = new RazorView(viewEngine, _pageActivator, _viewStartProvider, page, isPartial);
|
||||
var razorView = new RazorView(
|
||||
viewEngine,
|
||||
_pageActivator,
|
||||
_viewStartProvider,
|
||||
page,
|
||||
_htmlEncoder,
|
||||
isPartial);
|
||||
return razorView;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
/// <inheritdoc />
|
||||
public override void Write(string value)
|
||||
{
|
||||
Content.Append(value);
|
||||
Content.AppendEncoded(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(char value)
|
||||
{
|
||||
Content.Append(value.ToString());
|
||||
Content.AppendEncoded(value.ToString());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.Globalization;
|
|||
using System.Linq;
|
||||
using Microsoft.AspNet.Hosting;
|
||||
using Microsoft.AspNet.Mvc.Razor.TagHelpers;
|
||||
using Microsoft.AspNet.Mvc.Rendering;
|
||||
using Microsoft.AspNet.Mvc.TagHelpers.Internal;
|
||||
using Microsoft.AspNet.Razor.Runtime.TagHelpers;
|
||||
using Microsoft.Framework.Caching.Memory;
|
||||
|
|
@ -265,7 +266,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
{
|
||||
// Only HrefInclude is specified. Don't render the original tag.
|
||||
output.TagName = null;
|
||||
output.Content.SetContent(string.Empty);
|
||||
output.Content.SetContent(HtmlString.Empty);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -323,26 +324,27 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
}
|
||||
}
|
||||
|
||||
builder.Append(Environment.NewLine);
|
||||
builder.Append(HtmlString.NewLine);
|
||||
|
||||
// Build the <meta /> tag that's used to test for the presence of the stylesheet
|
||||
builder.AppendFormat(
|
||||
CultureInfo.InvariantCulture,
|
||||
"<meta name=\"x-stylesheet-fallback-test\" class=\"{0}\" />",
|
||||
HtmlEncoder.HtmlEncode(FallbackTestClass));
|
||||
builder
|
||||
.AppendEncoded("<meta name=\"x-stylesheet-fallback-test\" class=\"")
|
||||
.Append(FallbackTestClass)
|
||||
.AppendEncoded("\" />");
|
||||
|
||||
// Build the <script /> tag that checks the effective style of <meta /> tag above and renders the extra
|
||||
// <link /> tag to load the fallback stylesheet if the test CSS property value is found to be false,
|
||||
// indicating that the primary stylesheet failed to load.
|
||||
builder
|
||||
.Append("<script>")
|
||||
.AppendFormat(
|
||||
CultureInfo.InvariantCulture,
|
||||
JavaScriptResources.GetEmbeddedJavaScript(FallbackJavaScriptResourceName),
|
||||
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestProperty),
|
||||
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestValue),
|
||||
JavaScriptStringArrayEncoder.Encode(JavaScriptEncoder, fallbackHrefs))
|
||||
.Append("</script>");
|
||||
.AppendEncoded("<script>")
|
||||
.AppendEncoded(
|
||||
string.Format(
|
||||
CultureInfo.InvariantCulture,
|
||||
JavaScriptResources.GetEmbeddedJavaScript(FallbackJavaScriptResourceName),
|
||||
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestProperty),
|
||||
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestValue),
|
||||
JavaScriptStringArrayEncoder.Encode(JavaScriptEncoder, fallbackHrefs)))
|
||||
.AppendEncoded("</script>");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -370,7 +372,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
|
||||
private void BuildLinkTag(TagHelperAttributeList attributes, TagHelperContent builder)
|
||||
{
|
||||
builder.Append("<link ");
|
||||
builder.AppendEncoded("<link ");
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
|
|
@ -389,13 +391,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
}
|
||||
|
||||
builder
|
||||
.Append(attribute.Name)
|
||||
.Append("=\"")
|
||||
.AppendEncoded(attribute.Name)
|
||||
.AppendEncoded("=\"")
|
||||
.Append(HtmlEncoder, ViewContext.Writer.Encoding, attributeValue)
|
||||
.Append("\" ");
|
||||
.AppendEncoded("\" ");
|
||||
}
|
||||
|
||||
builder.Append("/>");
|
||||
builder.AppendEncoded("/>");
|
||||
}
|
||||
|
||||
private enum Mode
|
||||
|
|
|
|||
|
|
@ -282,10 +282,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
if (fallbackSrcs.Any())
|
||||
{
|
||||
// Build the <script> tag that checks the test method and if it fails, renders the extra script.
|
||||
builder.Append(Environment.NewLine)
|
||||
.Append("<script>(")
|
||||
.Append(FallbackTestExpression)
|
||||
.Append("||document.write(\"");
|
||||
builder.AppendEncoded(Environment.NewLine)
|
||||
.AppendEncoded("<script>(")
|
||||
.AppendEncoded(FallbackTestExpression)
|
||||
.AppendEncoded("||document.write(\"");
|
||||
|
||||
// May have no "src" attribute in the dictionary e.g. if Src and SrcInclude were not bound.
|
||||
if (!attributes.ContainsName(SrcAttributeName))
|
||||
|
|
@ -299,7 +299,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
// Fallback "src" values come from bound attributes and globbing. Must always be non-null.
|
||||
Debug.Assert(src != null);
|
||||
|
||||
builder.Append("<script");
|
||||
builder.AppendEncoded("<script");
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
|
|
@ -327,10 +327,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
}
|
||||
}
|
||||
|
||||
builder.Append("><\\/script>");
|
||||
builder.AppendEncoded("><\\/script>");
|
||||
}
|
||||
|
||||
builder.Append("\"));</script>");
|
||||
builder.AppendEncoded("\"));</script>");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -360,7 +360,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
TagHelperAttributeList attributes,
|
||||
TagHelperContent builder)
|
||||
{
|
||||
builder.Append("<script");
|
||||
builder.AppendEncoded("<script");
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
|
|
@ -381,29 +381,29 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
AppendAttribute(builder, attribute.Name, attributeValue, escapeQuotes: false);
|
||||
}
|
||||
|
||||
builder.Append("></script>");
|
||||
builder.AppendEncoded("></script>");
|
||||
}
|
||||
|
||||
private void AppendAttribute(TagHelperContent content, string key, object value, bool escapeQuotes)
|
||||
{
|
||||
content
|
||||
.Append(" ")
|
||||
.Append(key);
|
||||
.AppendEncoded(" ")
|
||||
.AppendEncoded(key);
|
||||
if (escapeQuotes)
|
||||
{
|
||||
// Passed only JavaScript-encoded strings in this case. Do not perform HTML-encoding as well.
|
||||
content
|
||||
.Append("=\\\"")
|
||||
.Append((string)value)
|
||||
.Append("\\\"");
|
||||
.AppendEncoded("=\\\"")
|
||||
.AppendEncoded((string)value)
|
||||
.AppendEncoded("\\\"");
|
||||
}
|
||||
else
|
||||
{
|
||||
// HTML-encoded the given value if necessary.
|
||||
content
|
||||
.Append("=\"")
|
||||
.AppendEncoded("=\"")
|
||||
.Append(HtmlEncoder, ViewContext.Writer.Encoding, value)
|
||||
.Append("\"");
|
||||
.AppendEncoded("\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -283,7 +283,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
|
||||
var innerContent = new BufferedHtmlContent();
|
||||
innerContent.Append(templateBuilderResult);
|
||||
innerContent.Append(" ");
|
||||
innerContent.AppendEncoded(" ");
|
||||
innerContent.Append(htmlHelper.ValidationMessage(
|
||||
propertyMetadata.PropertyName,
|
||||
message: null,
|
||||
|
|
|
|||
|
|
@ -539,8 +539,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
// The first newline is always trimmed when a TextArea is rendered, so we add an extra one
|
||||
// in case the value being rendered is something like "\r\nHello".
|
||||
var innerContent = new BufferedHtmlContent();
|
||||
innerContent.Append(Environment.NewLine);
|
||||
innerContent.Append(new StringHtmlContent(value));
|
||||
innerContent.Append(HtmlString.NewLine);
|
||||
innerContent.Append(value);
|
||||
tagBuilder.InnerHtml = innerContent;
|
||||
|
||||
return tagBuilder;
|
||||
|
|
@ -704,7 +704,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
|
||||
if (!isHtmlSummaryModified)
|
||||
{
|
||||
htmlSummary.AppendLine(HiddenListItem);
|
||||
htmlSummary.AppendEncoded(HiddenListItem);
|
||||
htmlSummary.Append(HtmlString.NewLine);
|
||||
}
|
||||
|
||||
var unorderedList = new TagBuilder("ul")
|
||||
|
|
@ -1316,7 +1317,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
groupBuilder.MergeAttribute("disabled", "disabled");
|
||||
}
|
||||
|
||||
var optGroupContent = new BufferedHtmlContent().Append(Environment.NewLine);
|
||||
var optGroupContent = new BufferedHtmlContent().Append(HtmlString.NewLine);
|
||||
foreach (var item in group)
|
||||
{
|
||||
optGroupContent.AppendLine(GenerateOption(item));
|
||||
|
|
|
|||
|
|
@ -1,6 +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 System;
|
||||
using System.IO;
|
||||
using Microsoft.AspNet.Html.Abstractions;
|
||||
using Microsoft.Framework.Internal;
|
||||
|
|
@ -20,6 +21,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
/// </summary>
|
||||
public static readonly HtmlString Empty = new HtmlString(string.Empty);
|
||||
|
||||
/// <summary>
|
||||
/// Returns an <see cref="HtmlString"/> containing <see cref="Environment.NewLine"/>.
|
||||
/// </summary>
|
||||
public static readonly HtmlString NewLine = new HtmlString(Environment.NewLine);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="HtmlString"/>.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -2,9 +2,11 @@
|
|||
// 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 System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Html.Abstractions;
|
||||
using Microsoft.Framework.Internal;
|
||||
using Microsoft.Framework.WebEncoders;
|
||||
|
||||
|
|
@ -19,8 +21,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
/// </remarks>
|
||||
public class StringCollectionTextWriter : TextWriter
|
||||
{
|
||||
private const int MaxCharToStringLength = 1024;
|
||||
private static readonly Task _completedTask = Task.FromResult(0);
|
||||
|
||||
private readonly Encoding _encoding;
|
||||
private readonly StringCollectionTextWriterContent _content;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of <see cref="StringCollectionTextWriter"/>.
|
||||
|
|
@ -29,7 +34,8 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
public StringCollectionTextWriter(Encoding encoding)
|
||||
{
|
||||
_encoding = encoding;
|
||||
Content = new BufferedHtmlContent();
|
||||
Entries = new List<object>();
|
||||
_content = new StringCollectionTextWriterContent(Entries);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -39,15 +45,17 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// A collection of entries buffered by this instance of <see cref="StringCollectionTextWriter"/>.
|
||||
/// Gets the content written to the writer as an <see cref="IHtmlContent"/>.
|
||||
/// </summary>
|
||||
public IHtmlContent Content => _content;
|
||||
|
||||
// internal for testing purposes.
|
||||
internal BufferedHtmlContent Content { get; }
|
||||
internal List<object> Entries { get; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Write(char value)
|
||||
{
|
||||
Content.Append(value.ToString());
|
||||
_content.Append(value.ToString());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -62,7 +70,19 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
throw new ArgumentOutOfRangeException(nameof(count));
|
||||
}
|
||||
|
||||
Content.Append(buffer, index, count);
|
||||
while (count > 0)
|
||||
{
|
||||
// Split large char arrays into 1KB strings.
|
||||
var currentCount = count;
|
||||
if (MaxCharToStringLength < currentCount)
|
||||
{
|
||||
currentCount = MaxCharToStringLength;
|
||||
}
|
||||
|
||||
_content.Append(new string(buffer, index, currentCount));
|
||||
index += currentCount;
|
||||
count -= currentCount;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -73,7 +93,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
return;
|
||||
}
|
||||
|
||||
Content.Append(value);
|
||||
_content.Append(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -100,7 +120,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
/// <inheritdoc />
|
||||
public override void WriteLine()
|
||||
{
|
||||
Content.Append(Environment.NewLine);
|
||||
_content.Append(Environment.NewLine);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
|
@ -149,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
var targetStringCollectionWriter = writer as StringCollectionTextWriter;
|
||||
if (targetStringCollectionWriter != null)
|
||||
{
|
||||
targetStringCollectionWriter.Content.Append(Content);
|
||||
targetStringCollectionWriter._content.Append(Content);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -178,5 +198,46 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
return writer.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
internal class StringCollectionTextWriterContent : IHtmlContent
|
||||
{
|
||||
private readonly List<object> _entries;
|
||||
|
||||
public StringCollectionTextWriterContent(List<object> entries)
|
||||
{
|
||||
_entries = entries;
|
||||
}
|
||||
|
||||
public void Append(string value)
|
||||
{
|
||||
_entries.Add(value);
|
||||
}
|
||||
|
||||
public void Append(IHtmlContent content)
|
||||
{
|
||||
_entries.Add(content);
|
||||
}
|
||||
|
||||
public void WriteTo(TextWriter writer, IHtmlEncoder encoder)
|
||||
{
|
||||
foreach (var item in _entries)
|
||||
{
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var itemAsString = item as string;
|
||||
if (itemAsString != null)
|
||||
{
|
||||
writer.Write(itemAsString);
|
||||
}
|
||||
else
|
||||
{
|
||||
((IHtmlContent)item).WriteTo(writer, encoder);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
var page = CreatePage(v =>
|
||||
{
|
||||
v.HtmlEncoder = new CommonTestEncoder();
|
||||
v.StartTagHelperWritingScope(new RazorTextWriter(TextWriter.Null, Encoding.UTF8));
|
||||
v.StartTagHelperWritingScope(new RazorTextWriter(TextWriter.Null, Encoding.UTF8, v.HtmlEncoder));
|
||||
v.Write("Hello ");
|
||||
v.Write("World!");
|
||||
var returnValue = v.EndTagHelperWritingScope();
|
||||
|
|
@ -1018,15 +1018,11 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
public async Task Write_WithHtmlString_WritesValueWithoutEncoding()
|
||||
{
|
||||
// Arrange
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var stringCollectionWriter = new StringCollectionTextWriter(Encoding.UTF8);
|
||||
stringCollectionWriter.Write("text1");
|
||||
stringCollectionWriter.Write("text2");
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
var page = CreatePage(p =>
|
||||
{
|
||||
p.Write(new HtmlString("Hello world"));
|
||||
p.Write(stringCollectionWriter.Content);
|
||||
});
|
||||
page.ViewContext.Writer = writer;
|
||||
|
||||
|
|
@ -1034,11 +1030,9 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
await page.ExecuteAsync();
|
||||
|
||||
// Assert
|
||||
var buffer = writer.BufferedWriter.Content.Entries;
|
||||
Assert.Equal(3, buffer.Count);
|
||||
var buffer = writer.BufferedWriter.Entries;
|
||||
Assert.Equal(1, buffer.Count);
|
||||
Assert.Equal("Hello world", buffer[0]);
|
||||
Assert.Equal("text1", buffer[1]);
|
||||
Assert.Equal("text2", buffer[2]);
|
||||
}
|
||||
|
||||
public static TheoryData<TagHelperOutput, string> WriteTagHelper_InputData
|
||||
|
|
@ -1688,7 +1682,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
uniqueId: string.Empty,
|
||||
executeChildContentAsync: () =>
|
||||
{
|
||||
defaultTagHelperContent.SetContent(input);
|
||||
defaultTagHelperContent.AppendEncoded(input);
|
||||
return Task.FromResult(result: true);
|
||||
},
|
||||
startTagHelperWritingScope: () => { },
|
||||
|
|
@ -1726,11 +1720,12 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
startTagHelperWritingScope: () => { },
|
||||
endTagHelperWritingScope: () => new DefaultTagHelperContent());
|
||||
tagHelperExecutionContext.Output = new TagHelperOutput("p", new TagHelperAttributeList());
|
||||
tagHelperExecutionContext.Output.Content.SetContent("Hello World!");
|
||||
tagHelperExecutionContext.Output.Content.AppendEncoded("Hello World!");
|
||||
|
||||
// Act
|
||||
var page = CreatePage(p =>
|
||||
{
|
||||
p.HtmlEncoder = new CommonTestEncoder();
|
||||
p.WriteTagHelperToAsync(writer, tagHelperExecutionContext).Wait();
|
||||
}, context);
|
||||
await page.ExecuteAsync();
|
||||
|
|
@ -1783,11 +1778,11 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
TagMode = tagMode
|
||||
};
|
||||
|
||||
output.PreElement.SetContent(preElement);
|
||||
output.PreContent.SetContent(preContent);
|
||||
output.Content.SetContent(content);
|
||||
output.PostContent.SetContent(postContent);
|
||||
output.PostElement.SetContent(postElement);
|
||||
output.PreElement.AppendEncoded(preElement);
|
||||
output.PreContent.AppendEncoded(preContent);
|
||||
output.Content.AppendEncoded(content);
|
||||
output.PostContent.AppendEncoded(postContent);
|
||||
output.PostElement.AppendEncoded(postElement);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ using System.IO;
|
|||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Testing;
|
||||
using Microsoft.Framework.WebEncoders.Testing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -20,7 +21,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
{
|
||||
// Arrange
|
||||
var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718", "m" };
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
writer.Write(true);
|
||||
|
|
@ -32,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
writer.Write('m');
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, writer.BufferedWriter.Content.Entries);
|
||||
Assert.Equal(expected, writer.BufferedWriter.Entries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -42,7 +43,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
// Arrange
|
||||
var expected = new[] { "True", "3", "18446744073709551615", "Hello world", "3.14", "2.718" };
|
||||
var unbufferedWriter = new Mock<TextWriter>();
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8, new CommonTestEncoder());
|
||||
var testClass = new TestClass();
|
||||
|
||||
// Act
|
||||
|
|
@ -55,7 +56,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
writer.Write(2.718m);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(writer.BufferedWriter.Content.Entries);
|
||||
Assert.Empty(writer.BufferedWriter.Entries);
|
||||
foreach (var item in expected)
|
||||
{
|
||||
unbufferedWriter.Verify(v => v.Write(item), Times.Once());
|
||||
|
|
@ -68,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
{
|
||||
// Arrange
|
||||
var unbufferedWriter = new Mock<TextWriter> { CallBase = true };
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8, new CommonTestEncoder());
|
||||
var buffer1 = new[] { 'a', 'b', 'c', 'd' };
|
||||
var buffer2 = new[] { 'd', 'e', 'f' };
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
await writer.WriteLineAsync(buffer1);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(writer.BufferedWriter.Content.Entries);
|
||||
Assert.Empty(writer.BufferedWriter.Entries);
|
||||
unbufferedWriter.Verify(v => v.Write('x'), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.Write(buffer1, 1, 2), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.Write(buffer1, 0, 4), Times.Once());
|
||||
|
|
@ -96,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
{
|
||||
// Arrange
|
||||
var unbufferedWriter = new Mock<TextWriter>();
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
await writer.FlushAsync();
|
||||
|
|
@ -106,7 +107,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
await writer.WriteLineAsync("gh");
|
||||
|
||||
// Assert
|
||||
Assert.Empty(writer.BufferedWriter.Content.Entries);
|
||||
Assert.Empty(writer.BufferedWriter.Entries);
|
||||
unbufferedWriter.Verify(v => v.Write("a"), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.WriteLine("ab"), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.WriteAsync("ef"), Times.Once());
|
||||
|
|
@ -120,7 +121,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
// Arrange
|
||||
var newLine = Environment.NewLine;
|
||||
var expected = new List<object> { "False", newLine, "1.1", newLine, "3", newLine };
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
writer.WriteLine(false);
|
||||
|
|
@ -128,7 +129,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
writer.WriteLine(3L);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, writer.BufferedWriter.Content.Entries);
|
||||
Assert.Equal(expected, writer.BufferedWriter.Entries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -137,7 +138,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
{
|
||||
// Arrange
|
||||
var unbufferedWriter = new Mock<TextWriter>();
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
writer.Flush();
|
||||
|
|
@ -146,7 +147,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
writer.WriteLine(3L);
|
||||
|
||||
// Assert
|
||||
Assert.Empty(writer.BufferedWriter.Content.ToString());
|
||||
Assert.Empty(writer.BufferedWriter.Entries);
|
||||
unbufferedWriter.Verify(v => v.Write("False"), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.Write("1.1"), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.Write("3"), Times.Once());
|
||||
|
|
@ -160,7 +161,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
var input1 = new ArraySegment<char>(new char[] { 'a', 'b', 'c', 'd' }, 1, 3);
|
||||
var input2 = new ArraySegment<char>(new char[] { 'e', 'f' }, 0, 2);
|
||||
var input3 = new ArraySegment<char>(new char[] { 'g', 'h', 'i', 'j' }, 3, 1);
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
writer.Write(input1.Array, input1.Offset, input1.Count);
|
||||
|
|
@ -168,7 +169,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
await writer.WriteLineAsync(input3.Array, input3.Offset, input3.Count);
|
||||
|
||||
// Assert
|
||||
var buffer = writer.BufferedWriter.Content.Entries;
|
||||
var buffer = writer.BufferedWriter.Entries;
|
||||
Assert.Equal(4, buffer.Count);
|
||||
Assert.Equal("bcd", buffer[0]);
|
||||
Assert.Equal("ef", buffer[1]);
|
||||
|
|
@ -181,14 +182,14 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
{
|
||||
// Arrange
|
||||
var newLine = Environment.NewLine;
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
// Assert
|
||||
var actual = writer.BufferedWriter.Content.Entries;
|
||||
var actual = writer.BufferedWriter.Entries;
|
||||
Assert.Equal<object>(new[] { newLine, newLine }, actual);
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +202,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
var input2 = "from";
|
||||
var input3 = "ASP";
|
||||
var input4 = ".Net";
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var writer = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
writer.Write(input1);
|
||||
|
|
@ -210,7 +211,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
await writer.WriteLineAsync(input4);
|
||||
|
||||
// Assert
|
||||
var actual = writer.BufferedWriter.Content.Entries;
|
||||
var actual = writer.BufferedWriter.Entries;
|
||||
Assert.Equal<object>(new[] { input1, input2, newLine, input3, input4, newLine }, actual);
|
||||
}
|
||||
|
||||
|
|
@ -218,8 +219,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
public void Copy_CopiesContent_IfTargetTextWriterIsARazorTextWriterAndBuffering()
|
||||
{
|
||||
// Arrange
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
source.Write("Hello world");
|
||||
|
|
@ -228,9 +229,9 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
|
||||
// Assert
|
||||
// Make sure content was written to the source.
|
||||
Assert.Equal(2, source.BufferedWriter.Content.Entries.Count);
|
||||
Assert.Equal(1, target.BufferedWriter.Content.Entries.Count);
|
||||
Assert.Same(source.BufferedWriter.Content, Assert.Single(target.BufferedWriter.Content.Entries));
|
||||
Assert.Equal(2, source.BufferedWriter.Entries.Count);
|
||||
Assert.Equal(1, target.BufferedWriter.Entries.Count);
|
||||
Assert.Same(source.BufferedWriter.Content, Assert.Single(target.BufferedWriter.Entries));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -238,8 +239,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
{
|
||||
// Arrange
|
||||
var unbufferedWriter = new Mock<TextWriter>();
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8);
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
target.Flush();
|
||||
|
|
@ -249,8 +250,8 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
|
||||
// Assert
|
||||
// Make sure content was written to the source.
|
||||
Assert.Equal(2, source.BufferedWriter.Content.Entries.Count);
|
||||
Assert.Empty(target.BufferedWriter.Content.ToString());
|
||||
Assert.Equal(2, source.BufferedWriter.Entries.Count);
|
||||
Assert.Empty(target.BufferedWriter.Entries);
|
||||
unbufferedWriter.Verify(v => v.Write("Hello world"), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.Write("bc"), Times.Once());
|
||||
}
|
||||
|
|
@ -259,7 +260,7 @@ namespace Microsoft.AspNet.Mvc.Razor.Test
|
|||
public void Copy_WritesContent_IfTargetTextWriterIsNotARazorTextWriter()
|
||||
{
|
||||
// Arrange
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
var target = new StringWriter();
|
||||
var expected = @"Hello world
|
||||
abc";
|
||||
|
|
@ -277,8 +278,8 @@ abc";
|
|||
public async Task CopyAsync_WritesContent_IfTargetTextWriterIsARazorTextWriterAndBuffering()
|
||||
{
|
||||
// Arrange
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
var target = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
source.WriteLine("Hello world");
|
||||
|
|
@ -286,9 +287,9 @@ abc";
|
|||
await source.CopyToAsync(target);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(3, source.BufferedWriter.Content.Entries.Count);
|
||||
Assert.Equal(1, target.BufferedWriter.Content.Entries.Count);
|
||||
Assert.Equal(source.BufferedWriter.Content, Assert.Single(target.BufferedWriter.Content.Entries));
|
||||
Assert.Equal(3, source.BufferedWriter.Entries.Count);
|
||||
Assert.Equal(1, target.BufferedWriter.Entries.Count);
|
||||
Assert.Equal(source.BufferedWriter.Content, Assert.Single(target.BufferedWriter.Entries));
|
||||
}
|
||||
|
||||
//[Fact]
|
||||
|
|
@ -297,8 +298,8 @@ abc";
|
|||
{
|
||||
// Arrange
|
||||
var unbufferedWriter = new Mock<TextWriter>();
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8);
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
var target = new RazorTextWriter(unbufferedWriter.Object, Encoding.UTF8, new CommonTestEncoder());
|
||||
|
||||
// Act
|
||||
await target.FlushAsync();
|
||||
|
|
@ -308,7 +309,7 @@ abc";
|
|||
|
||||
// Assert
|
||||
// Make sure content was written to the source.
|
||||
Assert.Equal(3, source.BufferedWriter.Content.Entries.Count);
|
||||
Assert.Equal(3, source.BufferedWriter.Entries.Count);
|
||||
Assert.Empty(target.BufferedWriter.Content.ToString());
|
||||
unbufferedWriter.Verify(v => v.WriteAsync("Hello from Asp.Net"), Times.Once());
|
||||
unbufferedWriter.Verify(v => v.WriteAsync(Environment.NewLine), Times.Once());
|
||||
|
|
@ -319,7 +320,7 @@ abc";
|
|||
public async Task CopyAsync_WritesContent_IfTargetTextWriterIsNotARazorTextWriter()
|
||||
{
|
||||
// Arrange
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8);
|
||||
var source = new RazorTextWriter(TextWriter.Null, Encoding.UTF8, new CommonTestEncoder());
|
||||
var target = new StringWriter();
|
||||
var expected = @"Hello world
|
||||
";
|
||||
|
|
|
|||
|
|
@ -1,6 +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.Framework.WebEncoders.Testing;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -16,7 +17,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
// Arrange
|
||||
var factory = new RazorViewFactory(
|
||||
Mock.Of<IRazorPageActivator>(),
|
||||
Mock.Of<IViewStartProvider>());
|
||||
Mock.Of<IViewStartProvider>(),
|
||||
new CommonTestEncoder());
|
||||
var page = Mock.Of<IRazorPage>();
|
||||
var viewEngine = Mock.Of<IRazorViewEngine>();
|
||||
|
||||
|
|
@ -35,7 +37,8 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
// Arrange
|
||||
var factory = new RazorViewFactory(
|
||||
Mock.Of<IRazorPageActivator>(),
|
||||
Mock.Of<IViewStartProvider>());
|
||||
Mock.Of<IViewStartProvider>(),
|
||||
new CommonTestEncoder());
|
||||
|
||||
var page = Mock.Of<IRazorPage>();
|
||||
var viewEngine = Mock.Of<IRazorViewEngine>();
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: true);
|
||||
var viewContext = CreateViewContext(view);
|
||||
var expected = viewContext.Writer;
|
||||
|
|
@ -68,6 +69,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
activator.Object,
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: true);
|
||||
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
|
@ -131,6 +133,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
activator,
|
||||
CreateViewStartProvider(viewStart),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
|
@ -155,6 +158,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
activator.Object,
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: true);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -199,6 +203,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
viewStartProvider,
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: true);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -224,6 +229,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
var original = viewContext.Writer;
|
||||
|
|
@ -248,6 +254,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
var original = viewContext.Writer;
|
||||
|
|
@ -274,6 +281,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
activator.Object,
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -316,6 +324,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
activator.Object,
|
||||
CreateViewStartProvider(viewStart1, viewStart2),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -348,6 +357,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
Mock.Of<IViewStartProvider>(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewEngine.Setup(v => v.FindPage(viewContext, layoutPath))
|
||||
|
|
@ -411,6 +421,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
activator.Object,
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewEngine.Setup(p => p.FindPage(viewContext, LayoutPath))
|
||||
|
|
@ -452,6 +463,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -514,6 +526,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -571,6 +584,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -630,6 +644,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -694,6 +709,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -725,6 +741,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -784,6 +801,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -847,6 +865,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -899,6 +918,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -948,6 +968,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -977,6 +998,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -1021,6 +1043,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -1096,6 +1119,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
viewStartProvider.Object,
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewContext.HttpContext.Features.Set<IPageExecutionListenerFeature>(feature.Object);
|
||||
|
|
@ -1141,6 +1165,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
Mock.Of<IViewStartProvider>(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: true);
|
||||
var viewContext = CreateViewContext(view);
|
||||
viewContext.Writer = writer;
|
||||
|
|
@ -1172,6 +1197,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
Mock.Of<IViewStartProvider>(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -1211,6 +1237,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(viewStart1, viewStart2),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -1248,6 +1275,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(viewStart1, viewStart2),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -1288,6 +1316,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(viewStart),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: false);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
@ -1313,6 +1342,7 @@ namespace Microsoft.AspNet.Mvc.Razor
|
|||
Mock.Of<IRazorPageActivator>(),
|
||||
CreateViewStartProvider(),
|
||||
page,
|
||||
new CommonTestEncoder(),
|
||||
isPartial: true);
|
||||
var viewContext = CreateViewContext(view);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
{
|
||||
TagMode = TagMode.SelfClosing,
|
||||
};
|
||||
output.Content.SetContent(originalContent);
|
||||
output.Content.AppendEncoded(originalContent);
|
||||
var htmlGenerator = new TestableHtmlGenerator(new EmptyModelMetadataProvider());
|
||||
var tagHelper = GetTagHelper(htmlGenerator, model: false, propertyName: nameof(Model.IsACar));
|
||||
|
||||
|
|
@ -270,9 +270,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
{
|
||||
TagMode = TagMode.SelfClosing,
|
||||
};
|
||||
output.PreContent.SetContent(expectedPreContent);
|
||||
output.Content.SetContent(originalContent);
|
||||
output.PostContent.SetContent(expectedPostContent);
|
||||
output.PreContent.AppendEncoded(expectedPreContent);
|
||||
output.Content.AppendEncoded(originalContent);
|
||||
output.PostContent.AppendEncoded(expectedPostContent);
|
||||
|
||||
var htmlGenerator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
|
||||
var tagHelper = GetTagHelper(htmlGenerator.Object, model: false, propertyName: nameof(Model.IsACar));
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
getChildContentAsync: useCachedResult =>
|
||||
{
|
||||
var tagHelperContent = new DefaultTagHelperContent();
|
||||
tagHelperContent.SetContent(tagHelperOutputContent.OriginalChildContent);
|
||||
tagHelperContent.AppendEncoded(tagHelperOutputContent.OriginalChildContent);
|
||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||
});
|
||||
var htmlAttributes = new TagHelperAttributeList
|
||||
|
|
@ -204,14 +204,14 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
{ "class", "form-control" },
|
||||
};
|
||||
var output = new TagHelperOutput(expectedTagName, htmlAttributes);
|
||||
output.PreContent.SetContent(expectedPreContent);
|
||||
output.PostContent.SetContent(expectedPostContent);
|
||||
output.PreContent.AppendEncoded(expectedPreContent);
|
||||
output.PostContent.AppendEncoded(expectedPostContent);
|
||||
|
||||
// LabelTagHelper checks IsContentModified so we don't want to forcibly set it if
|
||||
// tagHelperOutputContent.OriginalContent is going to be null or empty.
|
||||
if (!string.IsNullOrEmpty(tagHelperOutputContent.OriginalContent))
|
||||
{
|
||||
output.Content.SetContent(tagHelperOutputContent.OriginalContent);
|
||||
output.Content.AppendEncoded(tagHelperOutputContent.OriginalContent);
|
||||
}
|
||||
|
||||
var viewContext = TestableHtmlGenerator.GetViewContext(model, htmlGenerator, metadataProvider);
|
||||
|
|
|
|||
|
|
@ -293,16 +293,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
getChildContentAsync: useCachedResult =>
|
||||
{
|
||||
var tagHelperContent = new DefaultTagHelperContent();
|
||||
tagHelperContent.SetContent("Something");
|
||||
tagHelperContent.AppendEncoded("Something");
|
||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||
});
|
||||
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||
{
|
||||
TagMode = TagMode.SelfClosing,
|
||||
};
|
||||
output.PreContent.SetContent(expectedPreContent);
|
||||
output.Content.SetContent(expectedContent);
|
||||
output.PostContent.SetContent(originalPostContent);
|
||||
output.PreContent.AppendEncoded(expectedPreContent);
|
||||
output.Content.AppendEncoded(expectedContent);
|
||||
output.PostContent.AppendEncoded(originalPostContent);
|
||||
|
||||
var htmlGenerator = new TestableHtmlGenerator(metadataProvider)
|
||||
{
|
||||
|
|
@ -395,16 +395,16 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
getChildContentAsync: useCachedResult =>
|
||||
{
|
||||
var tagHelperContent = new DefaultTagHelperContent();
|
||||
tagHelperContent.SetContent("Something");
|
||||
tagHelperContent.AppendEncoded("Something");
|
||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||
});
|
||||
var output = new TagHelperOutput(expectedTagName, originalAttributes)
|
||||
{
|
||||
TagMode = TagMode.SelfClosing,
|
||||
};
|
||||
output.PreContent.SetContent(expectedPreContent);
|
||||
output.Content.SetContent(expectedContent);
|
||||
output.PostContent.SetContent(originalPostContent);
|
||||
output.PreContent.AppendEncoded(expectedPreContent);
|
||||
output.Content.AppendEncoded(expectedContent);
|
||||
output.PostContent.AppendEncoded(originalPostContent);
|
||||
|
||||
var htmlGenerator = new TestableHtmlGenerator(metadataProvider)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
var output = new TagHelperOutput(
|
||||
"span",
|
||||
attributes: new TagHelperAttributeList());
|
||||
output.Content.SetContent(outputContent);
|
||||
output.Content.AppendEncoded(outputContent);
|
||||
|
||||
var context = new TagHelperContext(
|
||||
allAttributes: new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>(
|
||||
|
|
@ -177,7 +177,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
|
|||
getChildContentAsync: useCachedResult =>
|
||||
{
|
||||
var tagHelperContent = new DefaultTagHelperContent();
|
||||
tagHelperContent.SetContent(childContent);
|
||||
tagHelperContent.AppendEncoded(childContent);
|
||||
return Task.FromResult<TagHelperContent>(tagHelperContent);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNet.Html.Abstractions;
|
||||
using Microsoft.AspNet.Mvc.ModelBinding;
|
||||
using Microsoft.AspNet.Mvc.TestCommon;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
|
@ -151,7 +152,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
var actual = helper.Partial("some-partial");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, actual.ToString());
|
||||
Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(actual));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -166,7 +167,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
var actual = helper.Partial("some-partial", model);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, actual.ToString());
|
||||
Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(actual));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -182,7 +183,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
var actual = helper.Partial("some-partial", viewData);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, actual.ToString());
|
||||
Assert.Equal(expected, HtmlContentUtilities.HtmlContentToString(actual));
|
||||
}
|
||||
|
||||
private sealed class TestModel
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
writer.Write('m');
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, writer.Content.Entries);
|
||||
Assert.Equal(expected, writer.Entries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -51,7 +51,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
writer.WriteLine(3L);
|
||||
|
||||
// Assert
|
||||
Assert.Equal(expected, writer.Content.Entries);
|
||||
Assert.Equal(expected, writer.Entries);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
@ -69,7 +69,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
await writer.WriteLineAsync(input3.Array, input3.Offset, input3.Count);
|
||||
|
||||
// Assert
|
||||
var buffer = writer.Content.Entries;
|
||||
var buffer = writer.Entries;
|
||||
Assert.Equal(4, buffer.Count);
|
||||
Assert.Equal("bcd", buffer[0]);
|
||||
Assert.Equal("ef", buffer[1]);
|
||||
|
|
@ -89,7 +89,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
await writer.WriteLineAsync();
|
||||
|
||||
// Assert
|
||||
var actual = writer.Content.Entries;
|
||||
var actual = writer.Entries;
|
||||
Assert.Equal<object>(new[] { newLine, newLine }, actual);
|
||||
}
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
await writer.WriteLineAsync(input4);
|
||||
|
||||
// Assert
|
||||
var actual = writer.Content.Entries;
|
||||
var actual = writer.Entries;
|
||||
Assert.Equal(new[] { input1, input2, newLine, input3, input4, newLine }, actual);
|
||||
}
|
||||
|
||||
|
|
@ -129,11 +129,11 @@ namespace Microsoft.AspNet.Mvc.Rendering
|
|||
|
||||
// Assert
|
||||
// Make sure content was written to the source.
|
||||
Assert.Equal(2, source.Content.Entries.Count);
|
||||
Assert.Equal(1, target.Content.Entries.Count);
|
||||
var result = Assert.Single(target.Content.Entries);
|
||||
var bufferedHtmlContent = Assert.IsType<BufferedHtmlContent>(result);
|
||||
Assert.Same(source.Content.Entries, bufferedHtmlContent.Entries);
|
||||
Assert.Equal(2, source.Entries.Count);
|
||||
Assert.Equal(1, target.Entries.Count);
|
||||
|
||||
var entry = Assert.Single(target.Entries);
|
||||
Assert.Same(source.Content, entry);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
|||
|
|
@ -10,20 +10,16 @@ namespace ActivatorWebSite.TagHelpers
|
|||
[TargetElement("body")]
|
||||
public class FooterTagHelper : TagHelper
|
||||
{
|
||||
public FooterTagHelper(IHtmlEncoder encoder)
|
||||
{
|
||||
Encoder = encoder;
|
||||
}
|
||||
|
||||
public IHtmlEncoder Encoder { get; }
|
||||
|
||||
[HtmlAttributeNotBound]
|
||||
[ViewContext]
|
||||
public ViewContext ViewContext { get; set; }
|
||||
|
||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
output.PostContent.SetContent($"<footer>{Encoder.HtmlEncode((string)ViewContext.ViewData["footer"])}</footer>");
|
||||
output.PostContent
|
||||
.AppendEncoded("<footer>")
|
||||
.Append((string)ViewContext.ViewData["footer"])
|
||||
.AppendEncoded("</footer>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,7 @@ namespace TagHelpersWebSite.TagHelpers
|
|||
var childContent = await context.GetChildContentAsync();
|
||||
|
||||
// Find Urls in the content and replace them with their anchor tag equivalent.
|
||||
output.Content.SetContent(Regex.Replace(
|
||||
output.Content.AppendEncoded(Regex.Replace(
|
||||
childContent.GetContent(),
|
||||
@"\b(?:https?://|www\.)(\S+)\b",
|
||||
"<strong><a target=\"_blank\" href=\"http://$0\">$0</a></strong>"));
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ namespace TagHelpersWebSite.TagHelpers
|
|||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
output.Attributes.RemoveAll("bold");
|
||||
output.PreContent.SetContent("<b>");
|
||||
output.PostContent.SetContent("</b>");
|
||||
output.PreContent.AppendEncoded("<b>");
|
||||
output.PostContent.AppendEncoded("</b>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace TagHelpersWebSite.TagHelpers
|
|||
{
|
||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
output.Content.SetContent("nested-content");
|
||||
output.Content.AppendEncoded("nested-content");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ namespace TagHelpersWebSite.TagHelpers
|
|||
{
|
||||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
output.Content.SetContent("root-content");
|
||||
output.Content.AppendEncoded("root-content");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -23,8 +23,8 @@ namespace TagHelpersWebSite.TagHelpers
|
|||
{
|
||||
var surroundingTagName = Surround.ToLowerInvariant();
|
||||
|
||||
output.PreElement.SetContent($"<{surroundingTagName}>");
|
||||
output.PostElement.SetContent($"</{surroundingTagName}>");
|
||||
output.PreElement.AppendEncoded($"<{surroundingTagName}>");
|
||||
output.PostElement.AppendEncoded($"</{surroundingTagName}>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -50,7 +50,7 @@ namespace MvcSample.Web.Components
|
|||
writer));
|
||||
|
||||
output.TagName = null;
|
||||
output.Content.SetContent(writer.ToString());
|
||||
output.Content.AppendEncoded(writer.ToString());
|
||||
}
|
||||
|
||||
public async Task<IViewComponentResult> InvokeAsync(int count)
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ namespace TagHelpersWebSite.TagHelpers
|
|||
public override void Process(TagHelperContext context, TagHelperOutput output)
|
||||
{
|
||||
output.TagName = "section";
|
||||
output.PostContent.SetContent(string.Format(
|
||||
output.PostContent.AppendEncoded(string.Format(
|
||||
"<p><strong>Version:</strong> {0}</p>" + Environment.NewLine +
|
||||
"<p><strong>Copyright Year:</strong> {1}</p>" + Environment.NewLine +
|
||||
"<p><strong>Approved:</strong> {2}</p>" + Environment.NewLine +
|
||||
|
|
|
|||
Loading…
Reference in New Issue