Merge branch 'release/2.2'

This commit is contained in:
Doug Bunting 2018-07-23 15:38:40 -07:00
commit aedb05e5b6
No known key found for this signature in database
GPG Key ID: 888B4EB7822B32E9
2 changed files with 16 additions and 30 deletions

View File

@ -221,8 +221,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return; return;
} }
var stringValue = entry as string; if (entry is string stringValue)
if (stringValue != null)
{ {
encoder.Encode(writer, stringValue); encoder.Encode(writer, stringValue);
} }
@ -239,13 +238,11 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return; return;
} }
string entryAsString; if (entry is string entryAsString)
IHtmlContentContainer entryAsContainer;
if ((entryAsString = entry as string) != null)
{ {
destination.Append(entryAsString); destination.Append(entryAsString);
} }
else if ((entryAsContainer = entry as IHtmlContentContainer) != null) else if (entry is IHtmlContentContainer entryAsContainer)
{ {
entryAsContainer.CopyTo(destination); entryAsContainer.CopyTo(destination);
} }
@ -262,13 +259,11 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return; return;
} }
string entryAsString; if (entry is string entryAsString)
IHtmlContentContainer entryAsContainer;
if ((entryAsString = entry as string) != null)
{ {
destination.Append(entryAsString); destination.Append(entryAsString);
} }
else if ((entryAsContainer = entry as IHtmlContentContainer) != null) else if (entry is IHtmlContentContainer entryAsContainer)
{ {
entryAsContainer.MoveTo(destination); entryAsContainer.MoveTo(destination);
} }
@ -282,29 +277,19 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
{ {
if (entry == null) if (entry == null)
{ {
return false; return true;
} }
var stringValue = entry as string; if (entry is string stringValue)
if (stringValue != null)
{ {
// Do not encode the string because encoded value remains whitespace from user's POV. // Do not encode the string because encoded value remains whitespace from user's POV.
if (!string.IsNullOrWhiteSpace(stringValue)) return string.IsNullOrWhiteSpace(stringValue);
{
return false;
}
}
else
{
// Use NullHtmlEncoder to avoid treating encoded whitespace as non-whitespace e.g. "\t" as "	".
((IHtmlContent)entry).WriteTo(writer, NullHtmlEncoder.Default);
if (!writer.IsEmptyOrWhiteSpace)
{
return false;
}
} }
return true; // Use NullHtmlEncoder to avoid treating encoded whitespace as non-whitespace e.g. "\t" as "	".
((IHtmlContent)entry).WriteTo(writer, NullHtmlEncoder.Default);
return writer.IsEmptyOrWhiteSpace;
} }
private TagHelperContent AppendCore(object entry) private TagHelperContent AppendCore(object entry)

View File

@ -363,6 +363,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
{ {
return new TheoryData<string> return new TheoryData<string>
{ {
null,
string.Empty, string.Empty,
" ", " ",
"\n", "\n",