-
Notifications
You must be signed in to change notification settings - Fork 2.1k
TagBuilder fail with NPE if attribute have null value #4710
Comments
Good find! The workaround seems like it would be to just pass in |
if these behaviors are ok, I can send a PR
|
Issue #4078 says:
Is this (not support minimized attributes) "by design" or not? |
All of the quoted points are by design.
This is incorrect and not aligned with the rest of the |
@ctyar yes that behavior is by design. I think a point of comparison is to see what ASP.NET MVC 5.x did, and replicate that behavior. |
Looks like in MVC 5.x a I.e. this: var x = new TagBuilder("myTag");
x.Attributes["x"] = "v";
x.Attributes["y"] = "";
x.Attributes["z"] = null; Renders this: <myTag x="v" y="" z=""></myTag> So let's preserve that behavior. |
Fixed in 42dd449. |
Sample .cshtml code:
This tag builder will fail with
NullPointerException
while rendering with stacktrace:Tested on
Microsoft.AspNetCore.Mvc 1.0.0-rc2-final
.Investigation:
Line 208 of TagBuilder.AppendAttributes calls for
HtmlEncoder.Encode(writer, attribute.Value)
.But
TextEncoder.Encode(TextWriter output, string value)
is overload, requestingvalue.Length
.The text was updated successfully, but these errors were encountered: