Skip to content

Potential issue calling a partial with a partial parameter inside of an #each block #422

Closed
dotnet/arcade
#16884

Description

@HandleBarsNetQuestion

Hi, first post sorry if I screw this up.

I'm pretty sure the below is valid handlebars syntax, but it throws an exception. I'm not skilled enough yet to resolve it myself, sorry!

[Fact]
public void ThisWillThrowAnException()
{
    var handlebars = Handlebars.Create();
    handlebars.RegisterTemplate("testPartial", "arbitraryPartialContent");
    var source = "{{#each Fruits}}{{> testPartial aPartialParameter=\"couldBeAnything\"}}{{/each}}";
    var template = handlebars.Compile(source);
    var data = new
    {
        Fruits = new[] {"apple", "banana", "cherry" }
    };
    var result = template(data);
}

Exception info:

 HandlebarsDotNet.Test.IteratorTests.ThisWillThrowAnException
   Source: IteratorTests.cs line 14
   Duration: 141 ms

  Message: 
    System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace: 
    BindingContext.PopulateHash(HashParameterDictionary hash, Object from) line 167
    BindingContext.Initialize() line 101
    BindingContextPool.CreateContext(ICompiledHandlebarsConfiguration configuration, Object value, BindingContext parent, TemplateDelegate partialBlockTemplate) line 37
    BindingContext.Create(ICompiledHandlebarsConfiguration configuration, Object value, BindingContext parent, TemplateDelegate partialBlockTemplate) line 18
    BindingContext.CreateChildContext(Object value, TemplateDelegate partialBlockTemplate) line 154
    lambda_method(Closure , EncodedTextWriter& , BindingContext )
    ArrayIterator`1.Iterate(EncodedTextWriter& writer, BindingContext context, ChainSegment[] blockParamsVariables, Object input, TemplateDelegate template, TemplateDelegate ifEmpty) line 50
    IIterator.Iterate(EncodedTextWriter& writer, BindingContext context, ChainSegment[] blockParamsVariables, Object input, TemplateDelegate template, TemplateDelegate ifEmpty)
    Iterator.Iterate(BindingContext context, EncodedTextWriter writer, ChainSegment[] blockParamsVariables, Object target, TemplateDelegate template, TemplateDelegate ifEmpty) line 79
    lambda_method(Closure , EncodedTextWriter& , BindingContext )
    <>c__DisplayClass15_0.<Compile>b__0(TextWriter writer, Object context, Object data) line 169
    <>c__DisplayClass16_0.<Compile>b__0(Object context, Object data) line 183
    IteratorTests.ThisWillThrowAnException() line 24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions