parent
5d72a7f747
commit
42dd4499e0
|
|
@ -205,7 +205,7 @@ namespace Microsoft.AspNetCore.Mvc.Rendering
|
|||
writer.Write(" ");
|
||||
writer.Write(key);
|
||||
writer.Write("=\"");
|
||||
encoder.Encode(writer, attribute.Value);
|
||||
encoder.Encode(writer, attribute.Value ?? string.Empty);
|
||||
writer.Write("\"");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,6 +113,26 @@ namespace Microsoft.AspNetCore.Mvc.Core.Rendering
|
|||
Assert.Equal(output, result);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("attribute", "value", "<p attribute=\"HtmlEncode[[value]]\"></p>")]
|
||||
[InlineData("attribute", null, "<p attribute=\"\"></p>")]
|
||||
[InlineData("attribute", "", "<p attribute=\"\"></p>")]
|
||||
public void WriteTo_WriteEmptyAttribute_WhenValueIsNullOrEmpty(string attributeKey, string attributeValue, string expectedOutput)
|
||||
{
|
||||
// Arrange
|
||||
var tagBuilder = new TagBuilder("p");
|
||||
|
||||
// Act
|
||||
tagBuilder.Attributes.Add(attributeKey, attributeValue);
|
||||
|
||||
// Assert
|
||||
using (var writer = new StringWriter())
|
||||
{
|
||||
tagBuilder.WriteTo(writer, new HtmlTestEncoder());
|
||||
Assert.Equal(expectedOutput, writer.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteTo_IncludesInnerHtml()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue