React to BufferedHtmlContent changes

This changes all TagHelperContent methods to assume that input has NOT
YET been encoded.
This commit is contained in:
Ryan Nowak 2015-09-10 20:05:02 -07:00
parent 4fd866f340
commit fcadbc9095
3 changed files with 47 additions and 1 deletions

View File

@ -125,6 +125,12 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
return this;
}
public override TagHelperContent AppendEncoded(string value)
{
Buffer.AppendEncoded(value);
return this;
}
/// <inheritdoc />
public override TagHelperContent AppendFormat([NotNull] string format, object arg0)
{

View File

@ -59,6 +59,14 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
/// <returns>A reference to this instance after the append operation has completed.</returns>
public abstract TagHelperContent Append(string value);
/// <summary>
/// Appends <paramref name="value"/> to the existing content. <paramref name="value"/> is assumed
/// to be an HTML encoded <see cref="string"/> and no further encoding will be performed.
/// </summary>
/// <param name="value">The <see cref="string"/> to be appended.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
public abstract TagHelperContent AppendEncoded(string value);
/// <summary>
/// Appends the specified <paramref name="format"/> to the existing content after
/// replacing the format item with the <see cref="string"/> representation of the

View File

@ -613,7 +613,39 @@ namespace Microsoft.AspNet.Razor.Runtime.TagHelpers
tagHelperContent.WriteTo(writer, new CommonTestEncoder());
// Assert
Assert.Equal("Hello World", writer.ToString());
Assert.Equal("HtmlEncode[[Hello ]]HtmlEncode[[World]]", writer.ToString());
}
[Fact]
public void Append_WrittenAsEncoded()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.Append("Hi");
var writer = new StringWriter();
// Act
tagHelperContent.WriteTo(writer, new CommonTestEncoder());
// Assert
Assert.Equal("HtmlEncode[[Hi]]", writer.ToString());
}
[Fact]
public void AppendEncoded_DoesNotGetEncoded()
{
// Arrange
var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.AppendEncoded("Hi");
var writer = new StringWriter();
// Act
tagHelperContent.WriteTo(writer, new CommonTestEncoder());
// Assert
Assert.Equal("Hi", writer.ToString());
}
}
}