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 />
public override void Write(string value)
{
Content.AppendEncoded(value);
Content.AppendHtml(value);
}
/// <inheritdoc />
public override void Write(char value)
{
Content.AppendEncoded(value.ToString());
Content.AppendHtml(value.ToString());
}
/// <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
builder
.AppendEncoded("<meta name=\"x-stylesheet-fallback-test\" class=\"")
.AppendHtml("<meta name=\"x-stylesheet-fallback-test\" class=\"")
.Append(FallbackTestClass)
.AppendEncoded("\" />");
.AppendHtml("\" />");
// 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
.AppendEncoded("<script>")
.AppendEncoded(
.AppendHtml("<script>")
.AppendHtml(
string.Format(
CultureInfo.InvariantCulture,
JavaScriptResources.GetEmbeddedJavaScript(FallbackJavaScriptResourceName),
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestProperty),
JavaScriptEncoder.JavaScriptStringEncode(FallbackTestValue),
JavaScriptStringArrayEncoder.Encode(JavaScriptEncoder, fallbackHrefs)))
.AppendEncoded("</script>");
.AppendHtml("</script>");
}
}
@ -382,7 +382,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
private void BuildLinkTag(TagHelperAttributeList attributes, TagHelperContent builder)
{
builder.AppendEncoded("<link ");
builder.AppendHtml("<link ");
foreach (var attribute in attributes)
{
@ -401,13 +401,13 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
}
builder
.AppendEncoded(attribute.Name)
.AppendEncoded("=\"")
.AppendHtml(attribute.Name)
.AppendHtml("=\"")
.Append(HtmlEncoder, ViewContext.Writer.Encoding, attributeValue)
.AppendEncoded("\" ");
.AppendHtml("\" ");
}
builder.AppendEncoded("/>");
builder.AppendHtml("/>");
}
private enum Mode

View File

@ -293,10 +293,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.AppendEncoded(Environment.NewLine)
.AppendEncoded("<script>(")
.AppendEncoded(FallbackTestExpression)
.AppendEncoded("||document.write(\"");
builder.AppendHtml(Environment.NewLine)
.AppendHtml("<script>(")
.AppendHtml(FallbackTestExpression)
.AppendHtml("||document.write(\"");
// May have no "src" attribute in the dictionary e.g. if Src and SrcInclude were not bound.
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.
Debug.Assert(src != null);
builder.AppendEncoded("<script");
builder.AppendHtml("<script");
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,
TagHelperContent builder)
{
builder.AppendEncoded("<script");
builder.AppendHtml("<script");
foreach (var attribute in attributes)
{
@ -392,29 +392,29 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
AppendAttribute(builder, attribute.Name, attributeValue, escapeQuotes: false);
}
builder.AppendEncoded("></script>");
builder.AppendHtml("></script>");
}
private void AppendAttribute(TagHelperContent content, string key, object value, bool escapeQuotes)
{
content
.AppendEncoded(" ")
.AppendEncoded(key);
.AppendHtml(" ")
.AppendHtml(key);
if (escapeQuotes)
{
// Passed only JavaScript-encoded strings in this case. Do not perform HTML-encoding as well.
content
.AppendEncoded("=\\\"")
.AppendEncoded((string)value)
.AppendEncoded("\\\"");
.AppendHtml("=\\\"")
.AppendHtml((string)value)
.AppendHtml("\\\"");
}
else
{
// HTML-encoded the given value if necessary.
content
.AppendEncoded("=\"")
.AppendHtml("=\"")
.Append(HtmlEncoder, ViewContext.Writer.Encoding, value)
.AppendEncoded("\"");
.AppendHtml("\"");
}
}

View File

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

View File

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

View File

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

View File

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

View File

@ -204,17 +204,17 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
getChildContentAsync: useCachedResult =>
{
var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded(tagHelperOutputContent.OriginalChildContent);
tagHelperContent.AppendHtml(tagHelperOutputContent.OriginalChildContent);
return Task.FromResult<TagHelperContent>(tagHelperContent);
});
output.PreContent.AppendEncoded(expectedPreContent);
output.PostContent.AppendEncoded(expectedPostContent);
output.PreContent.AppendHtml(expectedPreContent);
output.PostContent.AppendHtml(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.AppendEncoded(tagHelperOutputContent.OriginalContent);
output.Content.AppendHtml(tagHelperOutputContent.OriginalContent);
}
var viewContext = TestableHtmlGenerator.GetViewContext(model, htmlGenerator, metadataProvider);

View File

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

View File

@ -146,7 +146,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
// Arrange
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-hello", "world");
@ -170,10 +170,10 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
getChildContentAsync: useCachedResult =>
{
var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded(childContent);
tagHelperContent.AppendHtml(childContent);
return Task.FromResult<TagHelperContent>(tagHelperContent);
});
output.Content.AppendEncoded(outputContent);
output.Content.AppendHtml(outputContent);
var context = new TagHelperContext(
allAttributes: new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>(
@ -205,7 +205,7 @@ namespace Microsoft.AspNet.Mvc.TagHelpers
{
// Arrange
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-hello", "world");

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@ namespace TagHelpersWebSite.TagHelpers
var childContent = await output.GetChildContentAsync();
// 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(),
@"\b(?:https?://|www\.)(\S+)\b",
"<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)
{
output.Attributes.RemoveAll("bold");
output.PreContent.AppendEncoded("<b>");
output.PostContent.AppendEncoded("</b>");
output.PreContent.AppendHtml("<b>");
output.PostContent.AppendHtml("</b>");
}
}
}

View File

@ -10,7 +10,7 @@ namespace TagHelpersWebSite.TagHelpers
{
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)
{
output.Content.AppendEncoded("root-content");
output.Content.AppendHtml("root-content");
}
}
}

View File

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

View File

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

View File

@ -14,7 +14,7 @@ namespace TagHelpersWebSite.TagHelpers
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "section";
output.PostContent.AppendEncoded(string.Format(
output.PostContent.AppendHtml(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 +