You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's possible to get the compiled renderer to throw a null reference exception by adding a null item to a list in the model and then iterating over the list and accessing a property in the template.
Model:
publicclass ExampleClass
{publicstring Bar {get;}="Test"}var input =new{
Examples =newList<ExampleClass>(){null}}
Template:
{{#Examples}} {{Bar}} {{/Examples}}
If you execute a compiled renderer function for that template with the example input you will get a NullReferenceException. I ran into this on a simple template & input model, but it could be a nightmare to debug with a complex model & template since there's no debug information other than the exception type.
I think a null check in the expression returned by CompilerContext.Lookup would be helpful? In my case I would prefer an exception to be thrown that has some information such as the name of the variable that failed and location in the template or context path that led to the variable.
The text was updated successfully, but these errors were encountered:
Thanks for reporting this and submitting a PR. This was entirely an oversight in the compilation renderer design. I've approached the solution in a slightly different way which makes all access safe.
It's possible to get the compiled renderer to throw a null reference exception by adding a null item to a list in the model and then iterating over the list and accessing a property in the template.
Model:
Template:
If you execute a compiled renderer function for that template with the example input you will get a
NullReferenceException
. I ran into this on a simple template & input model, but it could be a nightmare to debug with a complex model & template since there's no debug information other than the exception type.I think a null check in the expression returned by CompilerContext.Lookup would be helpful? In my case I would prefer an exception to be thrown that has some information such as the name of the variable that failed and location in the template or context path that led to the variable.
The text was updated successfully, but these errors were encountered: