Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

TagBuilder fail with NPE if attribute have null value  #4710

Closed
@justdmitry

Description

@justdmitry

Sample .cshtml code:

<html><body>
    @{
        var tb = new TagBuilder("span");
        tb.Attributes.Add("dummy", null);
        tb.InnerHtml.Append("Hello, World!");
    }
    @tb
</body></html>

This tag builder will fail with NullPointerException while rendering with stacktrace:

System.NullReferenceException: Object reference not set to an instance of an object.
   at Microsoft.AspNetCore.Mvc.Rendering.TagBuilder.AppendAttributes(TextWriter writer, HtmlEncoder encoder)
   at Microsoft.AspNetCore.Mvc.Rendering.TagBuilder.WriteTo(TextWriter writer, HtmlEncoder encoder)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewBuffer.<WriteToAsync>d__18.MoveNext()

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, requesting value.Length.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3 - Donebugup-for-grabsMembers of our awesome commnity can handle this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions