Rename `AppendEncoded()` to `AppendHtml()` and `SetContentEncoded()` to `SetHtmlContent()`

- #3225, 3 of 3
This commit is contained in:
Doug Bunting 2015-10-21 15:44:51 -07:00
parent 2b9dae572e
commit c267ef3904
20 changed files with 71 additions and 71 deletions

View File

@ -54,13 +54,13 @@ namespace Microsoft.AspNet.Mvc.Razor
/// <inheritdoc /> /// <inheritdoc />
public override void Write(string value) public override void Write(string value)
{ {
Content.AppendEncoded(value); Content.AppendHtml(value);
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Write(char value) public override void Write(char value)
{ {
Content.AppendEncoded(value.ToString()); Content.AppendHtml(value.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -338,23 +338,23 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Build the <meta /> tag that's used to test for the presence of the stylesheet // Build the <meta /> tag that's used to test for the presence of the stylesheet
builder builder
.AppendEncoded("<meta name=\"x-stylesheet-fallback-test\" class=\"") .AppendHtml("<meta name=\"x-stylesheet-fallback-test\" class=\"")
.Append(FallbackTestClass) .Append(FallbackTestClass)
.AppendEncoded("\" />"); .AppendHtml("\" />");
// Build the <script /> tag that checks the effective style of <meta /> tag above and renders the extra // 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, // <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. // indicating that the primary stylesheet failed to load.
builder builder
.AppendEncoded("<script>") .AppendHtml("<script>")
.AppendEncoded( .AppendHtml(
string.Format( string.Format(
CultureInfo.InvariantCulture, CultureInfo.InvariantCulture,
JavaScriptResources.GetEmbeddedJavaScript(FallbackJavaScriptResourceName), JavaScriptResources.GetEmbeddedJavaScript(FallbackJavaScriptResourceName),
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestProperty), JavaScriptEncoder.JavaScriptStringEncode(FallbackTestProperty),
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestValue), JavaScriptEncoder.JavaScriptStringEncode(FallbackTestValue),
JavaScriptStringArrayEncoder.Encode(JavaScriptEncoder, fallbackHrefs))) JavaScriptStringArrayEncoder.Encode(JavaScriptEncoder, fallbackHrefs)))
.AppendEncoded("</script>"); .AppendHtml("</script>");
} }
} }
@ -382,7 +382,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
private void BuildLinkTag(TagHelperAttributeList attributes, TagHelperContent builder) private void BuildLinkTag(TagHelperAttributeList attributes, TagHelperContent builder)
{ {
builder.AppendEncoded("<link "); builder.AppendHtml("<link ");
foreach (var attribute in attributes) foreach (var attribute in attributes)
{ {
@ -401,13 +401,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
} }
builder builder
.AppendEncoded(attribute.Name) .AppendHtml(attribute.Name)
.AppendEncoded("=\"") .AppendHtml("=\"")
.Append(HtmlEncoder, ViewContext.Writer.Encoding, attributeValue) .Append(HtmlEncoder, ViewContext.Writer.Encoding, attributeValue)
.AppendEncoded("\" "); .AppendHtml("\" ");
} }
builder.AppendEncoded("/>"); builder.AppendHtml("/>");
} }
private enum Mode private enum Mode

View File

@ -293,10 +293,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
if (fallbackSrcs.Any()) if (fallbackSrcs.Any())
{ {
// Build the <script> tag that checks the test method and if it fails, renders the extra script. // Build the <script> tag that checks the test method and if it fails, renders the extra script.
builder.AppendEncoded(Environment.NewLine) builder.AppendHtml(Environment.NewLine)
.AppendEncoded("<script>(") .AppendHtml("<script>(")
.AppendEncoded(FallbackTestExpression) .AppendHtml(FallbackTestExpression)
.AppendEncoded("||document.write(\""); .AppendHtml("||document.write(\"");
// May have no "src" attribute in the dictionary e.g. if Src and SrcInclude were not bound. // May have no "src" attribute in the dictionary e.g. if Src and SrcInclude were not bound.
if (!attributes.ContainsName(SrcAttributeName)) if (!attributes.ContainsName(SrcAttributeName))
@ -310,7 +310,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
// Fallback "src" values come from bound attributes and globbing. Must always be non-null. // Fallback "src" values come from bound attributes and globbing. Must always be non-null.
Debug.Assert(src != null); Debug.Assert(src != null);
builder.AppendEncoded("<script"); builder.AppendHtml("<script");
foreach (var attribute in attributes) foreach (var attribute in attributes)
{ {
@ -338,10 +338,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
} }
} }
builder.AppendEncoded("><\\/script>"); builder.AppendHtml("><\\/script>");
} }
builder.AppendEncoded("\"));</script>"); builder.AppendHtml("\"));</script>");
} }
} }
@ -371,7 +371,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
TagHelperAttributeList attributes, TagHelperAttributeList attributes,
TagHelperContent builder) TagHelperContent builder)
{ {
builder.AppendEncoded("<script"); builder.AppendHtml("<script");
foreach (var attribute in attributes) foreach (var attribute in attributes)
{ {
@ -392,29 +392,29 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
AppendAttribute(builder, attribute.Name, attributeValue, escapeQuotes: false); AppendAttribute(builder, attribute.Name, attributeValue, escapeQuotes: false);
} }
builder.AppendEncoded("></script>"); builder.AppendHtml("></script>");
} }
private void AppendAttribute(TagHelperContent content, string key, object value, bool escapeQuotes) private void AppendAttribute(TagHelperContent content, string key, object value, bool escapeQuotes)
{ {
content content
.AppendEncoded(" ") .AppendHtml(" ")
.AppendEncoded(key); .AppendHtml(key);
if (escapeQuotes) if (escapeQuotes)
{ {
// Passed only JavaScript-encoded strings in this case. Do not perform HTML-encoding as well. // Passed only JavaScript-encoded strings in this case. Do not perform HTML-encoding as well.
content content
.AppendEncoded("=\\\"") .AppendHtml("=\\\"")
.AppendEncoded((string)value) .AppendHtml((string)value)
.AppendEncoded("\\\""); .AppendHtml("\\\"");
} }
else else
{ {
// HTML-encoded the given value if necessary. // HTML-encoded the given value if necessary.
content content
.AppendEncoded("=\"") .AppendHtml("=\"")
.Append(HtmlEncoder, ViewContext.Writer.Encoding, value) .Append(HtmlEncoder, ViewContext.Writer.Encoding, value)
.AppendEncoded("\""); .AppendHtml("\"");
} }
} }

View File

@ -282,7 +282,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
valueDivTag.AddCssClass("editor-field"); valueDivTag.AddCssClass("editor-field");
valueDivTag.InnerHtml.Append(templateBuilderResult); valueDivTag.InnerHtml.Append(templateBuilderResult);
valueDivTag.InnerHtml.AppendEncoded(" "); valueDivTag.InnerHtml.AppendHtml(" ");
valueDivTag.InnerHtml.Append(htmlHelper.ValidationMessage( valueDivTag.InnerHtml.Append(htmlHelper.ValidationMessage(
propertyMetadata.PropertyName, propertyMetadata.PropertyName,
message: null, message: null,

View File

@ -818,7 +818,7 @@ namespace Microsoft.AspNet.Mvc.ViewFeatures
if (!isHtmlSummaryModified) if (!isHtmlSummaryModified)
{ {
htmlSummary.InnerHtml.AppendEncoded(HiddenListItem); htmlSummary.InnerHtml.AppendHtml(HiddenListItem);
htmlSummary.InnerHtml.AppendLine(); htmlSummary.InnerHtml.AppendLine();
} }

View File

@ -1658,7 +1658,7 @@ namespace Microsoft.AspNet.Mvc.Razor
uniqueId: string.Empty, uniqueId: string.Empty,
executeChildContentAsync: () => executeChildContentAsync: () =>
{ {
defaultTagHelperContent.AppendEncoded(input); defaultTagHelperContent.AppendHtml(input);
return Task.FromResult(result: true); return Task.FromResult(result: true);
}, },
startTagHelperWritingScope: () => { }, startTagHelperWritingScope: () => { },
@ -1702,7 +1702,7 @@ namespace Microsoft.AspNet.Mvc.Razor
tagName: "p", tagName: "p",
attributes: new TagHelperAttributeList(), attributes: new TagHelperAttributeList(),
getChildContentAsync: (_) => Task.FromResult<TagHelperContent>(new DefaultTagHelperContent())); getChildContentAsync: (_) => Task.FromResult<TagHelperContent>(new DefaultTagHelperContent()));
tagHelperExecutionContext.Output.Content.AppendEncoded("Hello World!"); tagHelperExecutionContext.Output.Content.AppendHtml("Hello World!");
// Act // Act
var page = CreatePage(p => var page = CreatePage(p =>
@ -1763,11 +1763,11 @@ namespace Microsoft.AspNet.Mvc.Razor
TagMode = tagMode TagMode = tagMode
}; };
output.PreElement.AppendEncoded(preElement); output.PreElement.AppendHtml(preElement);
output.PreContent.AppendEncoded(preContent); output.PreContent.AppendHtml(preContent);
output.Content.AppendEncoded(content); output.Content.AppendHtml(content);
output.PostContent.AppendEncoded(postContent); output.PostContent.AppendHtml(postContent);
output.PostElement.AppendEncoded(postElement); output.PostElement.AppendHtml(postElement);
return output; return output;
} }

View File

@ -98,7 +98,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
TagMode = TagMode.SelfClosing, TagMode = TagMode.SelfClosing,
}; };
output.Content.AppendEncoded(originalContent); output.Content.AppendHtml(originalContent);
var htmlGenerator = new TestableHtmlGenerator(new EmptyModelMetadataProvider()); var htmlGenerator = new TestableHtmlGenerator(new EmptyModelMetadataProvider());
var tagHelper = GetTagHelper(htmlGenerator, model: false, propertyName: nameof(Model.IsACar)); var tagHelper = GetTagHelper(htmlGenerator, model: false, propertyName: nameof(Model.IsACar));
@ -277,9 +277,9 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
TagMode = TagMode.SelfClosing, TagMode = TagMode.SelfClosing,
}; };
output.PreContent.AppendEncoded(expectedPreContent); output.PreContent.AppendHtml(expectedPreContent);
output.Content.AppendEncoded(originalContent); output.Content.AppendHtml(originalContent);
output.PostContent.AppendEncoded(expectedPostContent); output.PostContent.AppendHtml(expectedPostContent);
var htmlGenerator = new Mock<IHtmlGenerator>(MockBehavior.Strict); var htmlGenerator = new Mock<IHtmlGenerator>(MockBehavior.Strict);
var tagHelper = GetTagHelper(htmlGenerator.Object, model: false, propertyName: nameof(Model.IsACar)); var tagHelper = GetTagHelper(htmlGenerator.Object, model: false, propertyName: nameof(Model.IsACar));

View File

@ -204,17 +204,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
getChildContentAsync: useCachedResult => getChildContentAsync: useCachedResult =>
{ {
var tagHelperContent = new DefaultTagHelperContent(); var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded(tagHelperOutputContent.OriginalChildContent); tagHelperContent.AppendHtml(tagHelperOutputContent.OriginalChildContent);
return Task.FromResult<TagHelperContent>(tagHelperContent); return Task.FromResult<TagHelperContent>(tagHelperContent);
}); });
output.PreContent.AppendEncoded(expectedPreContent); output.PreContent.AppendHtml(expectedPreContent);
output.PostContent.AppendEncoded(expectedPostContent); output.PostContent.AppendHtml(expectedPostContent);
// LabelTagHelper checks IsContentModified so we don't want to forcibly set it if // LabelTagHelper checks IsContentModified so we don't want to forcibly set it if
// tagHelperOutputContent.OriginalContent is going to be null or empty. // tagHelperOutputContent.OriginalContent is going to be null or empty.
if (!string.IsNullOrEmpty(tagHelperOutputContent.OriginalContent)) if (!string.IsNullOrEmpty(tagHelperOutputContent.OriginalContent))
{ {
output.Content.AppendEncoded(tagHelperOutputContent.OriginalContent); output.Content.AppendHtml(tagHelperOutputContent.OriginalContent);
} }
var viewContext = TestableHtmlGenerator.GetViewContext(model, htmlGenerator, metadataProvider); var viewContext = TestableHtmlGenerator.GetViewContext(model, htmlGenerator, metadataProvider);

View File

@ -299,15 +299,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
getChildContentAsync: useCachedResult => getChildContentAsync: useCachedResult =>
{ {
var tagHelperContent = new DefaultTagHelperContent(); var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded("Something"); tagHelperContent.AppendHtml("Something");
return Task.FromResult<TagHelperContent>(tagHelperContent); return Task.FromResult<TagHelperContent>(tagHelperContent);
}) })
{ {
TagMode = TagMode.SelfClosing, TagMode = TagMode.SelfClosing,
}; };
output.PreContent.AppendEncoded(expectedPreContent); output.PreContent.AppendHtml(expectedPreContent);
output.Content.AppendEncoded(expectedContent); output.Content.AppendHtml(expectedContent);
output.PostContent.AppendEncoded(originalPostContent); output.PostContent.AppendHtml(originalPostContent);
var htmlGenerator = new TestableHtmlGenerator(metadataProvider) var htmlGenerator = new TestableHtmlGenerator(metadataProvider)
{ {
@ -403,15 +403,15 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
getChildContentAsync: useCachedResult => getChildContentAsync: useCachedResult =>
{ {
var tagHelperContent = new DefaultTagHelperContent(); var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded("Something"); tagHelperContent.AppendHtml("Something");
return Task.FromResult<TagHelperContent>(tagHelperContent); return Task.FromResult<TagHelperContent>(tagHelperContent);
}) })
{ {
TagMode = TagMode.SelfClosing, TagMode = TagMode.SelfClosing,
}; };
output.PreContent.AppendEncoded(expectedPreContent); output.PreContent.AppendHtml(expectedPreContent);
output.Content.AppendEncoded(expectedContent); output.Content.AppendHtml(expectedContent);
output.PostContent.AppendEncoded(originalPostContent); output.PostContent.AppendHtml(originalPostContent);
var htmlGenerator = new TestableHtmlGenerator(metadataProvider) var htmlGenerator = new TestableHtmlGenerator(metadataProvider)
{ {

View File

@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
// Arrange // Arrange
var tagBuilder = new TagBuilder("span2"); var tagBuilder = new TagBuilder("span2");
tagBuilder.InnerHtml.SetContentEncoded("New HTML"); tagBuilder.InnerHtml.SetHtmlContent("New HTML");
tagBuilder.Attributes.Add("data-foo", "bar"); tagBuilder.Attributes.Add("data-foo", "bar");
tagBuilder.Attributes.Add("data-hello", "world"); tagBuilder.Attributes.Add("data-hello", "world");
@ -170,10 +170,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
getChildContentAsync: useCachedResult => getChildContentAsync: useCachedResult =>
{ {
var tagHelperContent = new DefaultTagHelperContent(); var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded(childContent); tagHelperContent.AppendHtml(childContent);
return Task.FromResult<TagHelperContent>(tagHelperContent); return Task.FromResult<TagHelperContent>(tagHelperContent);
}); });
output.Content.AppendEncoded(outputContent); output.Content.AppendHtml(outputContent);
var context = new TagHelperContext( var context = new TagHelperContext(
allAttributes: new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>( allAttributes: new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>(
@ -205,7 +205,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
// Arrange // Arrange
var tagBuilder = new TagBuilder("span2"); var tagBuilder = new TagBuilder("span2");
tagBuilder.InnerHtml.SetContentEncoded("New HTML"); tagBuilder.InnerHtml.SetHtmlContent("New HTML");
tagBuilder.Attributes.Add("data-foo", "bar"); tagBuilder.Attributes.Add("data-foo", "bar");
tagBuilder.Attributes.Add("data-hello", "world"); tagBuilder.Attributes.Add("data-hello", "world");

View File

@ -140,7 +140,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
// Arrange // Arrange
var tagBuilder = new TagBuilder("span2"); var tagBuilder = new TagBuilder("span2");
tagBuilder.InnerHtml.SetContentEncoded("New HTML"); tagBuilder.InnerHtml.SetHtmlContent("New HTML");
tagBuilder.Attributes.Add("data-foo", "bar"); tagBuilder.Attributes.Add("data-foo", "bar");
tagBuilder.Attributes.Add("data-hello", "world"); tagBuilder.Attributes.Add("data-hello", "world");
tagBuilder.Attributes.Add("anything", "something"); tagBuilder.Attributes.Add("anything", "something");
@ -245,7 +245,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{ {
// Arrange // Arrange
var tagBuilder = new TagBuilder("span2"); var tagBuilder = new TagBuilder("span2");
tagBuilder.InnerHtml.SetContentEncoded("New HTML"); tagBuilder.InnerHtml.SetHtmlContent("New HTML");
var generator = new Mock<IHtmlGenerator>(); var generator = new Mock<IHtmlGenerator>();
generator generator

View File

@ -110,7 +110,7 @@ namespace Microsoft.AspNet.Mvc.Core.Rendering
{ {
// Arrange // Arrange
var tagBuilder = new TagBuilder("p"); var tagBuilder = new TagBuilder("p");
tagBuilder.InnerHtml.AppendEncoded("<span>Hello</span>"); tagBuilder.InnerHtml.AppendHtml("<span>Hello</span>");
tagBuilder.InnerHtml.Append(", World!"); tagBuilder.InnerHtml.Append(", World!");
// Act // Act

View File

@ -17,9 +17,9 @@ namespace ActivatorWebSite.TagHelpers
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)
{ {
output.PostContent output.PostContent
.AppendEncoded("<footer>") .AppendHtml("<footer>")
.Append((string)ViewContext.ViewData["footer"]) .Append((string)ViewContext.ViewData["footer"])
.AppendEncoded("</footer>"); .AppendHtml("</footer>");
} }
} }
} }

View File

@ -15,7 +15,7 @@ namespace TagHelpersWebSite.TagHelpers
var childContent = await output.GetChildContentAsync(); var childContent = await output.GetChildContentAsync();
// Find Urls in the content and replace them with their anchor tag equivalent. // Find Urls in the content and replace them with their anchor tag equivalent.
output.Content.AppendEncoded(Regex.Replace( output.Content.AppendHtml(Regex.Replace(
childContent.GetContent(), childContent.GetContent(),
@"\b(?:https?://|www\.)(\S+)\b", @"\b(?:https?://|www\.)(\S+)\b",
"<strong><a target=\"_blank\" href=\"http://$0\">$0</a></strong>")); "<strong><a target=\"_blank\" href=\"http://$0\">$0</a></strong>"));

View File

@ -19,8 +19,8 @@ namespace TagHelpersWebSite.TagHelpers
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)
{ {
output.Attributes.RemoveAll("bold"); output.Attributes.RemoveAll("bold");
output.PreContent.AppendEncoded("<b>"); output.PreContent.AppendHtml("<b>");
output.PostContent.AppendEncoded("</b>"); output.PostContent.AppendHtml("</b>");
} }
} }
} }

View File

@ -10,7 +10,7 @@ namespace TagHelpersWebSite.TagHelpers
{ {
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)
{ {
output.Content.AppendEncoded("nested-content"); output.Content.AppendHtml("nested-content");
} }
} }
} }

View File

@ -10,7 +10,7 @@ namespace TagHelpersWebSite.TagHelpers
{ {
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)
{ {
output.Content.AppendEncoded("root-content"); output.Content.AppendHtml("root-content");
} }
} }
} }

View File

@ -23,8 +23,8 @@ namespace TagHelpersWebSite.TagHelpers
{ {
var surroundingTagName = Surround.ToLowerInvariant(); var surroundingTagName = Surround.ToLowerInvariant();
output.PreElement.AppendEncoded($"<{surroundingTagName}>"); output.PreElement.AppendHtml($"<{surroundingTagName}>");
output.PostElement.AppendEncoded($"</{surroundingTagName}>"); output.PostElement.AppendHtml($"</{surroundingTagName}>");
} }
} }
} }

View File

@ -56,7 +56,7 @@ namespace MvcSample.Web.Components
writer)); writer));
output.TagName = null; output.TagName = null;
output.Content.AppendEncoded(writer.ToString()); output.Content.AppendHtml(writer.ToString());
} }
public async Task<IViewComponentResult> InvokeAsync(int count) public async Task<IViewComponentResult> InvokeAsync(int count)

View File

@ -14,7 +14,7 @@ namespace TagHelpersWebSite.TagHelpers
public override void Process(TagHelperContext context, TagHelperOutput output) public override void Process(TagHelperContext context, TagHelperOutput output)
{ {
output.TagName = "section"; output.TagName = "section";
output.PostContent.AppendEncoded(string.Format( output.PostContent.AppendHtml(string.Format(
"<p><strong>Version:</strong> {0}</p>" + Environment.NewLine + "<p><strong>Version:</strong> {0}</p>" + Environment.NewLine +
"<p><strong>Copyright Year:</strong> {1}</p>" + Environment.NewLine + "<p><strong>Copyright Year:</strong> {1}</p>" + Environment.NewLine +
"<p><strong>Approved:</strong> {2}</p>" + Environment.NewLine + "<p><strong>Approved:</strong> {2}</p>" + Environment.NewLine +